public OutputStream createBodySink(@Nullable String contentEncoding) throws IOException { OutputStream deflatingOutput; ByteArrayOutputStream deflatedOutput = new ByteArrayOutputStream(); if (DecompressionHelper.GZIP_ENCODING.equals(contentEncoding)) { deflatingOutput = GunzippingOutputStream.create(deflatedOutput); } else if (DecompressionHelper.DEFLATE_ENCODING.equals(contentEncoding)) { deflatingOutput = new InflaterOutputStream(deflatedOutput); } else { deflatingOutput = deflatedOutput; } mDeflatingOutput = new CountingOutputStream(deflatingOutput); mDeflatedOutput = deflatedOutput; return mDeflatingOutput; }
@Test(timeout = 1000) public void testGunzip() throws IOException { byte[] data = "test123test123".getBytes(); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStream unzippingStream = GunzippingOutputStream.create(out); OutputStream zippingStream = new GZIPOutputStream(unzippingStream); zippingStream.write(data); zippingStream.close(); assertArrayEquals(data, out.toByteArray()); } }
decompressedCounter = new CountingOutputStream(decompressedOutput); if (gzipEncoding) { output = GunzippingOutputStream.create(decompressedCounter); } else if (deflateEncoding) { output = new InflaterOutputStream(decompressedCounter);