Problem ucompressing gz stream on the fly using GZIPInputStream

Joined
Apr 10, 2009
Messages
1
Reaction score
0
I am using Apache HttpClient to stream a gzipped file from a server. I retrieve the stream from the http response and wrap it with a GZIPInputStream and then attempt to read and print it using the following code:

Code:
GZIPInputStream  zipin = new GZIPInputStream(in);
int sChunk = 8192;
byte[] buffer = new byte[sChunk];
// decompress the file
int length;
while ((length = zipin.read(buffer, 0, sChunk)) != -1)
      System.out.write(buffer, 0, length);
zipin.close();
I would expect the contents of the file to be written out uncompressed but this is not so - the System.out writes out the binary data contents.

I know the file is ok, because if I save the file to disk and then read it in like this:

InputStream is = getClass().getResourceAsStream("data.txt.gz");
InputStream zipStream = new GZIPInputStream ( is );
System.out.println(IOUtils.toString(zipStream));

That actualy uncompresses it.. so what is wrong with uncompressing it on the fly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top