开发者

How to decompress a byte Array in Java

Can anybody tell me how to decompress a byte array?

Here is my code. I have been trying it for ages and it is giving me a DataFormatException.

byte bArray[] = new byte[tSizeOfTile];
input.read(bArray, offset, limit);

byte[] unComp = new byte[bArray.length + 100];

Inflater inflate = new Inflater();
inflate.setInput(bArray);
inflate.inflate(unComp, offset, bArray.length + 100);
inflate.e开发者_StackOverflownd();


Well, one definite issue is that you're apparently using InputStream.read without checking the return value. That means you may have read less data than you expected to.

Also, you're trying to inflate into unComp from the offset, but with a maximum length being the same as unComp.length. That means if offset is anything other than 0, you could be trying to write past the end of the array.

Did you mean the offset to refer to the input array? I don't believe that's what it means. You should use setInput to only provide input data.

However, you could make all of this a lot easier for yourself by using InflaterInputStream instead of handling Inflate yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜