data.mark();
boolean is_gzip = (data.remaining() >= 2 && data.getShort() == GZIP_MAGIC);
data.reset();
if (is_gzip) {
final Inflater inflater = new Inflater(true);
inflater.setInput(contents.array(), 0, contents.limit());
byte[] buf = new byte[4096];
ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.limit());
try {
while (! inflater.finished()) {
int inflated = inflater.inflate(buf, 0, buf.length);
baos.write(buf, 0, inflated);
}
} catch (Exception e) {
log.severe("DB| inflation error: "+e.getMessage());
log.log(Level.FINE, "details: ", e);