ZLib Inflate of Arbitrary Length Output?
Greetings. I have a question regarding java.util.zip.Inflater, used for zlib.
The class seems pretty straightforward, but I have trouble creating the output buffer because it is unknown size. Now, before you go yelling at me to go find out the size or for not keeping track of the size, let me give you a little background info. I'm working on a project opening files that a previous programmer left over. You can yell at him all you want, but he seems to have failed to record the output size - but was nice enough to include the input size.
So my question is simply, is there any way to Inflate a zlib into an arbitrary-length buffer? Maybe there's some method or something to find the size, or could I perhaps use a resizable data structure, or anything along those lines? I tried taking the Input buffer and multiplying it by 12, but sometimes zlib compression works so well that the resulting file is 1/100th the size of the original, and the output file becomes corrupted. I don't really want to use 100x, because then I can have a lot of leftover bytes, or it might still be too small.
Here's the code that I'm using so far, whereb is an array of bytes (the input), andlength is the size of the array. The end result is then stored in the array of bytesresult.
Inflater decompresser2 =new Inflater();
decompresser2.setInput(b);
byte[] result =newbyte[length * 12];
decompresser2.inflate(result);
int totalsize = decompresser2.getTotalOut();
decompresser2.end();
Inflater decompresser =new Inflater();
decompresser.setInput(b);
result =newbyte[totalsize];
decompresser.inflate(result);
decompresser.end();
First, I do a dummy uncompress to 12 times the original size (and cross my fingers hoping that it didn't compress better than 12x) to find out the output size. I then uncompress again, this time to the actual size.
Message was edited by:
IsmAvatar

