B K wrote:
to return the inputstream. I now have a requirement to determine how large
the compressed response is(to determine bandwidth usage), as the server is
not returning content-length I thought I would do the following
Can you not just keep track of how much data you have read from the stream?
As the response body is wrapped by GZIPInputStream I don't believe I would
be able to do this for a true indication of bw, please correct me if Im
wrong.
create a string buffer
create a buffered reader for getResponseBodyAsStream()
read the response and append to my string buffer
Bad idea!
You try to mix binary data with character data without any care for
character encodings. What method do you use to append data to the buffer?
If you want to do this, then put the data into a ByteArrayOutputStream
instead of a StringBuffer. Then you have binary data.
I gave this a go, with the understanding it may require a permanent solution
later, so i coded the following to see if it works
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedReader br = new BufferedReader(new
InputStreamReader(method.getResponseBodyAsStream()));
String line = br.readLine();
while (line != null) {
baos.write(line.getBytes());
line = br.readLine();
}
br.close();
method.releaseConnection();
return new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
However I get exactly the same result, I thought this is what you meant to
try? If not please excuse my ignorance.
Now at this point I have a stringbuffer with the compressed content, I can
use this to get the response length.
No, you can get the number of characters, not the same thing.
Note: since you do not know in advance how much data you will get you risk
getting OOME if the server sends a DVD or something other large.
/robo
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]