Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream read incomplete

900538Nov 16 2011 — edited Nov 16 2011
Hi!

I'm trying to read a byte array from an url. Sometimes it works fine an all data is received, but other times it is incomplete. In that cases, if I read from the InputStream again, I receive the rest of the data. Sometimes one more read is enough, other times I need to read twice, other times three times.... It is a very unpredictable behavior.

Here is the code:

URL objURL = new URL(url);
HttpURLConnection objHTTPconn = (HttpURLConnection)objURL.openConnection();
InputStream is = objHTTPconn.getInputStream();
if(objHTTPconn.getContentLength() > 0){
byte [] content = new byte [objHTTPconn.getContentLength()];
int len = is.read(content, 0, objHTTPconn.getContentLength());
}
is.close();
.....

Is correct the behavior of the InputStream?I think it can be due to a network delay. Is it possible? Can it maybe be because of the size of the heap?

The code runs in an Oracle IAS 10g over Solaris OS 5.8.

Regards,

Ester
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 14 2011
Added on Nov 16 2011
2 comments
1,055 views