Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4053340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:26:05+00:00 2026-05-20T14:26:05+00:00

Given the following example code: somefile = new URL(http://somefile.rar); ReadableByteChannel rbc = Channels.newChannel(somefile.openStream()); FileOutputStream

  • 0

Given the following example code:

somefile = new URL("http://somefile.rar");
ReadableByteChannel rbc = Channels.newChannel(somefile.openStream());
FileOutputStream fos = new FileOutputStream("test");
long start = System.currentTimeMillis();
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
long end = System.currentTimeMillis();
System.out.println(end-start);

The file in question is 14MB. When I download it using the code above, it takes 26-30 seconds every time. I noticed that, when downloading it from java, there are periods where no bytes are being transferred at all. When I download the same file from, say, a browser, it downloads in 4 seconds or less. Any idea what the problem is here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:26:05+00:00Added an answer on May 20, 2026 at 2:26 pm

    Using channels is a nice idea, since you can this way avoid superfluous copying of data in memory. But you are using not a real socket-channel here, but a wrapper channel around the InputStream from your URL, which ruins your experience.

    You may be able to implement the HTTP protocol yourself using a SocketChannel, or find some library which allows this. (But then, if the result is sent using chunked-encoding, you’ll still have to parse this yourself.)

    So, the easier way would be to use simply the usual stream copying way given by the other answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given the following simple example: List<string> list = new List<string>() { One, Two, Three,
Given the following code from a Microsoft example: public class EngineMeasurementCollection : Collection<EngineMeasurement> {
I tried following the example given on MSDN , but my code does not
OK So I'm looking to redirect the following: http://www.example.org/tag/code To the following: http://www.example.org/tag.php?tag=code The
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
Given a sorted vector with a number of values, as in the following example:
Given the following code in Eclipse: import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; public class
Given the following example layout: test/ test.py formats/ __init__.py format_a.py format_b.py What I try
given the following code: public class MainFrame extends JFrame{ public MainFrame() throws HeadlessException {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.