I am using HTTPClient to connect to a web site which returns the response in GZip compressed format. I was previously just using

new GZIPInputStream(method.getResponseBodyAsStream()

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

create a string buffer
create a buffered reader for getResponseBodyAsStream()
read the response and append to my string buffer

Now at this point I have a stringbuffer with the compressed content, I can use this to get the response length.

Then I tried a

return new GZIPInputStream(new ByteArrayInputStream(sb.toString().getBytes()));

It falls over with the following

java.io.IOException: Corrupt GZIP trailer
        at java.util.zip.GZIPInputStream.readTrailer(Unknown Source)
        at java.util.zip.GZIPInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)

Anyone got any ideas what the issue might be? Thanks BK



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to