use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testCompressThenDecompress.
private void testCompressThenDecompress(StreamingCompressor compressor, byte[] origin) throws CompressionException, ExecutionException, InterruptedException {
ByteWriter writer = new ByteWriter(origin);
EntityStream uncompressedStream = EntityStreams.newEntityStream(writer);
EntityStream compressedStream = compressor.deflate(uncompressedStream);
EntityStream decompressedStream = compressor.inflate(compressedStream);
FutureCallback<byte[]> callback = new FutureCallback<byte[]>();
decompressedStream.setReader(new ByteReader(callback));
byte[] result = callback.get();
Assert.assertEquals(result, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testGzipCompressor.
@Test
public void testGzipCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new GzipCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'b');
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
IOUtils.write(origin, gzip);
gzip.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testDeflateCompressor.
@Test
public void testDeflateCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new DeflateCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream zlib = new DeflaterOutputStream(out);
IOUtils.write(origin, zlib);
zlib.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testBzip2Compressor.
@Test
public void testBzip2Compressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new Bzip2Compressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
BZip2CompressorOutputStream bzip = new BZip2CompressorOutputStream(out);
IOUtils.write(origin, bzip);
bzip.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
use of com.linkedin.r2.filter.compression.streaming.StreamingCompressor in project rest.li by linkedin.
the class TestStreamingCompression method testDeflateCompressor.
@Test
public void testDeflateCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException {
StreamingCompressor compressor = new DeflateCompressor(_executor);
final byte[] origin = new byte[BUF_SIZE];
Arrays.fill(origin, (byte) 'c');
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream zlib = new DeflaterOutputStream(out);
IOUtils.write(origin, zlib);
zlib.close();
byte[] compressed = out.toByteArray();
testCompress(compressor, origin, compressed);
testDecompress(compressor, origin, compressed);
testCompressThenDecompress(compressor, origin);
}
Aggregations