2

I'm using a InputStream buffer as following. I'd like to know when it is actually buffering (filling itself with data)... I'm feeding it with internet stream. I put Logs before and after len = in.read(buffer) but they are logged in the same time (so the process is not here).

    conn = new URL(StringUrls[0]).openConnection();
    conn.setReadTimeout(5000);
    conn.setConnectTimeout(5000);
    in = conn.getInputStream();
    int len=-1;
    buffer = new byte[1024];

    Log.v("buffer", "buffering...");

    len = in.read(buffer);

    Log.v("buffer", "buffered");
1
  • Can you please share the logs ? I am expecting there is a minute difference in milliseconds Commented Jan 22, 2014 at 15:58

1 Answer 1

2

http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[]) states:

This method blocks until input data is available, end of file is detected, or an exception is thrown.

In other words, it is being filled when it has the data to be filed with. When you open a connection, the data are ready to be read. That is why InputStream does not have to wait for anything.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.