M
Markus Barchfeld
When I create an InputStreamReader on an InputStream obtained from a
UrlConnection, I do not get all the data until I enter a sleep-call.
This seems to be a bug. Has anybody an explanation or a more
sophisticated workaround?
Thanks
Here is the code:
HttpURLConnection urlCon = (HttpURLConnection) new
URL("").openConnection();
urlCon.setRequestMethod("POST");
urlCon.setDoOutput(true);
// .. code for writing request data
urlCon.connect();
InputStream in = urlCon.getInputStream();
InputStreamReader inReader = new InputStreamReader(in);
StringBuffer content = new StringBuffer();
char[] chars = new char[1<<16];
while (inReader.ready()) {
int read = inReader.read(chars);
content.append(chars,0,read);
// the following sleep is necessary to obtain all the data
// from the InputStream, otherwise this loop exits before all
// the data has been read from the InputStream
try {
Thread.sleep(500) ;
} catch (InterruptedException e) {}
}
inReader.close() ;
UrlConnection, I do not get all the data until I enter a sleep-call.
This seems to be a bug. Has anybody an explanation or a more
sophisticated workaround?
Thanks
Here is the code:
HttpURLConnection urlCon = (HttpURLConnection) new
URL("").openConnection();
urlCon.setRequestMethod("POST");
urlCon.setDoOutput(true);
// .. code for writing request data
urlCon.connect();
InputStream in = urlCon.getInputStream();
InputStreamReader inReader = new InputStreamReader(in);
StringBuffer content = new StringBuffer();
char[] chars = new char[1<<16];
while (inReader.ready()) {
int read = inReader.read(chars);
content.append(chars,0,read);
// the following sleep is necessary to obtain all the data
// from the InputStream, otherwise this loop exits before all
// the data has been read from the InputStream
try {
Thread.sleep(500) ;
} catch (InterruptedException e) {}
}
inReader.close() ;