InputStream read incomplete
900538Nov 16 2011 — edited Nov 16 2011Hi!
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