Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unknown information about 'nowrap' option in java.util.zip.Inflater.

807600Sep 25 2007 — edited Sep 25 2007
Hi,
For example: I have compressed data (deflate) in byte array. And I want to uncompress the byte array:
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();
but sometimes I dont`t know, somebody set 'nowrap' on true or false.
If somebody compressed data by means of:
Deflater def = new Deflater(1, true);
then, when I will use:
Inflater decompresser = new Inflater(); // = new Inflater(false)
there is an exception:
java.util.zip.DataFormatException: unknown compression method
because, I had to use:
Inflater decompresser = new Inflater(true);
I have written a class in order to avoid this problem:
public class NewInflaterInputStream extends FilterInputStream
{
    public InflaterInputStream(InputStream in) throws IOException
    {
        super(in);
        in = new PushbackInputStream(in);
        int firstByte = in.read();
        ((PushbackInputStream) in).unread(firstByte);
        if (firstByte == 120)
            this.in = new java.util.zip.InflaterInputStream(in);
        else
            this.in =
                    new java.util.zip.InflaterInputStream(in, new Inflater(true));
    }
}
But, I think, it isn`t a good idea. Do you have any better idea?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2007
Added on Sep 25 2007
1 comment
531 views