Search in sources :

Example 16 with StreamingCompressor

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);
}
Also used : EntityStream(com.linkedin.r2.message.stream.entitystream.EntityStream) FutureCallback(com.linkedin.common.callback.FutureCallback)

Example 17 with StreamingCompressor

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);
}
Also used : GzipCompressor(com.linkedin.r2.filter.compression.streaming.GzipCompressor) GZIPOutputStream(java.util.zip.GZIPOutputStream) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 18 with StreamingCompressor

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);
}
Also used : DeflateCompressor(com.linkedin.r2.filter.compression.streaming.DeflateCompressor) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 19 with StreamingCompressor

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);
}
Also used : BZip2CompressorOutputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream) Bzip2Compressor(com.linkedin.r2.filter.compression.streaming.Bzip2Compressor) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 20 with StreamingCompressor

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);
}
Also used : DeflateCompressor(com.linkedin.r2.filter.compression.streaming.DeflateCompressor) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) StreamingCompressor(com.linkedin.r2.filter.compression.streaming.StreamingCompressor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Aggregations

StreamingCompressor (com.linkedin.r2.filter.compression.streaming.StreamingCompressor)13 EntityStream (com.linkedin.r2.message.stream.entitystream.EntityStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Test (org.testng.annotations.Test)8 FutureCallback (com.linkedin.common.callback.FutureCallback)7 StreamEncodingType (com.linkedin.r2.filter.compression.streaming.StreamEncodingType)4 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)4 StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)4 Bzip2Compressor (com.linkedin.r2.filter.compression.streaming.Bzip2Compressor)2 DeflateCompressor (com.linkedin.r2.filter.compression.streaming.DeflateCompressor)2 GzipCompressor (com.linkedin.r2.filter.compression.streaming.GzipCompressor)2 PartialReader (com.linkedin.r2.filter.compression.streaming.PartialReader)2 SnappyCompressor (com.linkedin.r2.filter.compression.streaming.SnappyCompressor)2 StreamException (com.linkedin.r2.message.stream.StreamException)2 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)2 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)2 CompositeWriter (com.linkedin.r2.message.stream.entitystream.CompositeWriter)2 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 BZip2CompressorOutputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream)2