want to provide to a client with an input stream that gets the content of a string in GZIP compressed format.
However, the util.zip.GZIPInputStream class can only be used to decompress, not compress data.
So I tried to use java.util.zip.DeflaterInputStream instead. However this does not seem to generate GZIP format - when I try to read the generated data back using a GZIPInputStream I get a "Not in GZIP format" error.
DeflaterInputStream can take an instance of a Deflater as its second argument and Deflater can be constructed with a second argument "nowrap" set to true. In that case, according to the docs, "if true then use GZIP compatible compression" I thought the DeflaterInputStream should generate GZIP compatible format, but I still get "Not in GZIP format".
Here is the code I use:
InputStream is = IOUtils.toInputStream(theString, theEncoding);
InputStream iscomp =
new DeflaterInputStream(is,new Deflater(6,true));
// pas iscomp to the client to read the content of theString
// in GZIP compressed format
Is there a way to create an input stream that will provide a GZIP compressed version of theString?
GZIPOutputStream would create the correct data but I cannot use it here because it is an output stream and not an input stream as required by the client.