hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Olofsson <r...@khelekore.org>
Subject Re: GZIP Response
Date Thu, 24 Aug 2006 17:21:29 GMT
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?

> 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.

> 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.


To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

View raw message