Java Code Examples for net.jpountz.lz4.LZ4Factory#fastCompressor()

The following examples show how to use net.jpountz.lz4.LZ4Factory#fastCompressor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lz4FrameEncoder.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
/**
     * Creates a new customizable LZ4 encoder.创建一个新的可定制的LZ4编码器。
     *
     * @param factory         user customizable {@link LZ4Factory} instance
     *                        which may be JNI bindings to the original C implementation, a pure Java implementation
     *                        or a Java implementation that uses the {@link sun.misc.Unsafe}
     * @param highCompressor  if {@code true} codec will use compressor which requires more memory
     *                        and is slower but compresses more efficiently
     * @param blockSize       the maximum number of bytes to try to compress at once,
     *                        must be >= 64 and <= 32 M
     * @param checksum        the {@link Checksum} instance to use to check data for integrity
     * @param maxEncodeSize   the maximum size for an encode (compressed) buffer
     */
public Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize,
                       Checksum checksum, int maxEncodeSize) {
    if (factory == null) {
        throw new NullPointerException("factory");
    }
    if (checksum == null) {
        throw new NullPointerException("checksum");
    }

    compressor = highCompressor ? factory.highCompressor() : factory.fastCompressor();
    this.checksum = ByteBufChecksum.wrapChecksum(checksum);

    compressionLevel = compressionLevel(blockSize);
    this.blockSize = blockSize;
    this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
    finished = false;
}
 
Example 2
Source File: LZ4CompressorTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if(args.length == 0){
            System.out.println("args[0] must be data file path");
            return;
        }
        LZ4Factory factory = LZ4Factory.fastestInstance();

        byte[] data = Files.toByteArray(new File(args[0]));
        final int decompressedLength = data.length;

        // compress data
        LZ4Compressor compressor = factory.fastCompressor();
        long start = System.currentTimeMillis();
        int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
        byte[] compressed = new byte[maxCompressedLength];
        int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);
        System.out.println("compress take:" + (System.currentTimeMillis() - start));
        System.out.println(compressedLength);

        // decompress data
        // - method 1: when the decompressed length is known
        LZ4FastDecompressor decompressor = factory.fastDecompressor();
        start = System.currentTimeMillis();
        byte[] restored = new byte[decompressedLength];
        int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);
        System.out.println("decompress take:" + (System.currentTimeMillis() - start));
        System.out.println(decompressedLength);
        // compressedLength == compressedLength2

        // - method 2: when the compressed length is known (a little slower)
        // the destination buffer needs to be over-sized
        LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();
        int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);
    }
 
Example 3
Source File: Lz4Compress.java    From compress with MIT License 5 votes vote down vote up
@Override
public byte[] compress(byte[] data) throws IOException {
	LZ4Factory factory = LZ4Factory.fastestInstance();
	ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
	LZ4Compressor compressor = factory.fastCompressor();
	LZ4BlockOutputStream compressedOutput = new LZ4BlockOutputStream(byteOutput, 2048, compressor);
	compressedOutput.write(data);
	compressedOutput.close();
	
	return byteOutput.toByteArray();
}
 
Example 4
Source File: LZ4CompressorTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if(args.length == 0){
            System.out.println("args[0] must be data file path");
            return;
        }
        LZ4Factory factory = LZ4Factory.fastestInstance();

        byte[] data = Files.toByteArray(new File(args[0]));
        final int decompressedLength = data.length;

        // compress data
        LZ4Compressor compressor = factory.fastCompressor();
        long start = System.currentTimeMillis();
        int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
        byte[] compressed = new byte[maxCompressedLength];
        int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);
        System.out.println("compress take:" + (System.currentTimeMillis() - start));
        System.out.println(compressedLength);

        // decompress data
        // - method 1: when the decompressed length is known
        LZ4FastDecompressor decompressor = factory.fastDecompressor();
        start = System.currentTimeMillis();
        byte[] restored = new byte[decompressedLength];
        int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);
        System.out.println("decompress take:" + (System.currentTimeMillis() - start));
        System.out.println(decompressedLength);
        // compressedLength == compressedLength2

        // - method 2: when the compressed length is known (a little slower)
        // the destination buffer needs to be over-sized
        LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();
        int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);
    }
 
Example 5
Source File: Lz4Compressor.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public Lz4Compressor(boolean unsafe, int bufferSize, boolean useHC) {
  super(bufferSize);
  LZ4Factory factory = (unsafe) ? LZ4Factory.unsafeInstance() : LZ4Factory.safeInstance();
  compressor = (useHC) ? factory.highCompressor() : factory.fastCompressor();
}
 
Example 6
Source File: FrameCompressor.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private LZ4Compressor()
{
    final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();
    compressor = lz4Factory.fastCompressor();
    decompressor = lz4Factory.decompressor();
}
 
Example 7
Source File: LZ4Compressor.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private LZ4Compressor()
{
    final LZ4Factory lz4Factory = LZ4Factory.fastestInstance();
    compressor = lz4Factory.fastCompressor();
    decompressor = lz4Factory.decompressor();
}