GzipProcessorUtils { public static ByteBuf toGzip(ByteBuf src) { if (CHECK) checkArgument(src.readRemaining() >= 0); Deflater compressor = ensureCompressor(); compressor.setInput(src.array(), src.head(), src.readRemaining()); compressor.finish(); int dataSize = src.readRemaining(); int crc = getCrc(src, dataSize); int maxDataSize = estimateMaxCompressedSize(dataSize); ByteBuf dst = ByteBufPool.allocate(GZIP_HEADER_SIZE + maxDataSize + GZIP_FOOTER_SIZE + SPARE_BYTES_COUNT); dst.put(GZIP_HEADER); dst = writeCompressedData(compressor, src, dst); dst.writeInt(Integer.reverseBytes(crc)); dst.writeInt(Integer.reverseBytes(dataSize)); moveCompressorToPool(compressor); src.recycle(); return dst; }  static ByteBuf fromGzip(ByteBuf src, int maxMessageSize); static ByteBuf toGzip(ByteBuf src); static final ParseException CORRUPTED_GZIP_HEADER; static final ParseException DECOMPRESSED_SIZE_EXCEEDS_EXPECTED_MAX_SIZE; static final ParseException COMPRESSED_DATA_WAS_NOT_READ_FULLY; static final ParseException DATA_FORMAT_EXCEPTION; static final ParseException ACTUAL_DECOMPRESSED_DATA_SIZE_IS_NOT_EQUAL_TO_EXPECTED; static final ParseException INCORRECT_ID_HEADER_BYTES; static final ParseException INCORRECT_UNCOMPRESSED_INPUT_SIZE; static final ParseException UNSUPPORTED_COMPRESSION_METHOD; }
@Test public void testGzipInputStreamCorrectlyDecodesDataEncoded() throws IOException { ByteBuf encodedData = toGzip(wrapUtf8(text)); ByteBuf decoded = decodeWithGzipInputStream(encodedData); assertEquals(text, decoded.asString(UTF_8)); }