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();
}
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);
}
}
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 !!!");
}
}
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 !!!");
}
}
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 !!!");
}
}
Aggregations