Search in sources :

Example 6 with LZ4Compressor

use of net.jpountz.lz4.LZ4Compressor in project druid by druid-io.

the class LZ4Transcoder method compress.

@Override
protected byte[] compress(byte[] in) {
    if (in == null) {
        throw new NullPointerException("Can't compress null");
    }
    LZ4Compressor compressor = lz4Factory.fastCompressor();
    byte[] out = new byte[compressor.maxCompressedLength(in.length)];
    int compressedLength = compressor.compress(in, 0, in.length, out, 0);
    getLogger().debug("Compressed %d bytes to %d", in.length, compressedLength);
    return ByteBuffer.allocate(Ints.BYTES + compressedLength).putInt(in.length).put(out, 0, compressedLength).array();
}
Also used : LZ4Compressor(net.jpountz.lz4.LZ4Compressor)

Example 7 with LZ4Compressor

use of net.jpountz.lz4.LZ4Compressor in project hadoop by apache.

the class TestCompressorDecompressor method testCompressorDecompressor.

@Test
public void testCompressorDecompressor() {
    // no more for this data
    int SIZE = 44 * 1024;
    byte[] rawData = generate(SIZE);
    try {
        CompressDecompressTester.of(rawData).withCompressDecompressPair(new SnappyCompressor(), new SnappyDecompressor()).withCompressDecompressPair(new Lz4Compressor(), new Lz4Decompressor()).withCompressDecompressPair(new BuiltInZlibDeflater(), new BuiltInZlibInflater()).withTestCases(ImmutableSet.of(CompressionTestStrategy.COMPRESS_DECOMPRESS_SINGLE_BLOCK, CompressionTestStrategy.COMPRESS_DECOMPRESS_BLOCK, CompressionTestStrategy.COMPRESS_DECOMPRESS_ERRORS, CompressionTestStrategy.COMPRESS_DECOMPRESS_WITH_EMPTY_STREAM)).test();
    } catch (Exception ex) {
        GenericTestUtils.assertExceptionContains("testCompressorDecompressor error !!!", ex);
    }
}
Also used : BuiltInZlibInflater(org.apache.hadoop.io.compress.zlib.BuiltInZlibInflater) SnappyDecompressor(org.apache.hadoop.io.compress.snappy.SnappyDecompressor) SnappyCompressor(org.apache.hadoop.io.compress.snappy.SnappyCompressor) Lz4Compressor(org.apache.hadoop.io.compress.lz4.Lz4Compressor) Lz4Decompressor(org.apache.hadoop.io.compress.lz4.Lz4Decompressor) BuiltInZlibDeflater(org.apache.hadoop.io.compress.zlib.BuiltInZlibDeflater) Test(org.junit.Test)

Example 8 with LZ4Compressor

use of net.jpountz.lz4.LZ4Compressor in project hadoop by apache.

the class TestLz4CompressorDecompressor method testCompressorCompressAIOBException.

//test on ArrayIndexOutOfBoundsException in {@code compressor.compress()}  
@Test
public void testCompressorCompressAIOBException() {
    try {
        Lz4Compressor compressor = new Lz4Compressor();
        byte[] bytes = generate(1024 * 6);
        compressor.setInput(bytes, 0, bytes.length);
        compressor.compress(new byte[] {}, 0, -1);
        fail("testCompressorCompressAIOBException error !!!");
    } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
    } catch (Exception e) {
        fail("testCompressorCompressAIOBException ex error !!!");
    }
}
Also used : Lz4Compressor(org.apache.hadoop.io.compress.lz4.Lz4Compressor) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with LZ4Compressor

use of net.jpountz.lz4.LZ4Compressor in project hadoop by apache.

the class TestLz4CompressorDecompressor method testCompressorSetInputAIOBException.

//test on ArrayIndexOutOfBoundsException in {@code compressor.setInput()}
@Test
public void testCompressorSetInputAIOBException() {
    try {
        Lz4Compressor compressor = new Lz4Compressor();
        compressor.setInput(new byte[] {}, -5, 10);
        fail("testCompressorSetInputAIOBException error !!!");
    } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
    } catch (Exception ex) {
        fail("testCompressorSetInputAIOBException ex error !!!");
    }
}
Also used : Lz4Compressor(org.apache.hadoop.io.compress.lz4.Lz4Compressor) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with LZ4Compressor

use of net.jpountz.lz4.LZ4Compressor in project hadoop by apache.

the class TestLz4CompressorDecompressor method testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize.

// test Lz4Compressor compressor.compress()  
@Test
public void testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize() {
    int BYTES_SIZE = 1024 * 64 + 1;
    try {
        Lz4Compressor compressor = new Lz4Compressor();
        byte[] bytes = generate(BYTES_SIZE);
        assertTrue("needsInput error !!!", compressor.needsInput());
        compressor.setInput(bytes, 0, bytes.length);
        byte[] emptyBytes = new byte[BYTES_SIZE];
        int csize = compressor.compress(emptyBytes, 0, bytes.length);
        assertTrue("testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize error !!!", csize != 0);
    } catch (Exception ex) {
        fail("testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize ex error !!!");
    }
}
Also used : Lz4Compressor(org.apache.hadoop.io.compress.lz4.Lz4Compressor) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Lz4Compressor (org.apache.hadoop.io.compress.lz4.Lz4Compressor)10 Test (org.junit.Test)10 IOException (java.io.IOException)9 Lz4Decompressor (org.apache.hadoop.io.compress.lz4.Lz4Decompressor)5 DataInputStream (java.io.DataInputStream)2 LZ4Compressor (net.jpountz.lz4.LZ4Compressor)2 BlockCompressorStream (org.apache.hadoop.io.compress.BlockCompressorStream)2 BlockDecompressorStream (org.apache.hadoop.io.compress.BlockDecompressorStream)2 SnappyCompressor (org.apache.hadoop.io.compress.snappy.SnappyCompressor)2 SnappyDecompressor (org.apache.hadoop.io.compress.snappy.SnappyDecompressor)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 SocketException (java.net.SocketException)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 Checksum (java.util.zip.Checksum)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 LZ4BlockOutputStream (net.jpountz.lz4.LZ4BlockOutputStream)1