byte[] inBytes = new byte[inBuffer.limit()];
inBuffer.get(inBytes).flip();
byte[] outBytes = new byte[inBytes.length * 2];
ByteBuffer outBuffer = ByteBuffer.allocate(outBytes.length);
outBuffer.setAutoExpand(true);
zStream.next_in = inBytes;
zStream.next_in_index = 0;
zStream.avail_in = inBytes.length;
zStream.next_out = outBytes;
zStream.next_out_index = 0;
zStream.avail_out = outBytes.length;
int retval = 0;
do {
retval = zStream.inflate(JZlib.Z_SYNC_FLUSH);
switch (retval) {
case JZlib.Z_OK:
// completed decompression, lets copy data and get out
case JZlib.Z_BUF_ERROR:
// need more space for output. store current output and get more
outBuffer.put(outBytes, 0, zStream.next_out_index);
zStream.next_out_index = 0;
zStream.avail_out = outBytes.length;
break;
default:
// unknown error
outBuffer.release();
outBuffer = null;
if (zStream.msg == null)
throw new IOException("Unknown error. Error code : "
+ retval);
else
throw new IOException("Unknown error. Error code : "
+ retval + " and message : " + zStream.msg);
}
} while (zStream.avail_in > 0);
return outBuffer.flip();
}