Class Compressor


  • public class Compressor
    extends java.lang.Object
    Compressor which can compress and decompress in various formats. This class is thread safe. Creating a reusable instance is faster than creating instances as needed.
    Author:
    bratseth
    • Constructor Detail

      • Compressor

        public Compressor()
        Creates a compressor with default settings.
      • Compressor

        public Compressor​(CompressionType type)
        Creates a compressor with a default compression type.
      • Compressor

        public Compressor​(CompressionType type,
                          int level,
                          double compressionThresholdFactor,
                          int compressMinSizeBytes)
        Creates a compressor.
        Parameters:
        type - the type of compression to use to compress data
        level - a number between 0 and 9 where a higher value means more compression
        compressionThresholdFactor - the compression factor we need to achieve to return the compressed data instead of raw data
        compressMinSizeBytes - the minimal input data size to perform compression
    • Method Detail

      • type

        public CompressionType type()
        Returns the default compression type used by this
      • level

        public int level()
        Returns the compression level this will use - a number between 0 and 9 where higher means more compression
      • compressionThresholdFactor

        public double compressionThresholdFactor()
        Returns the compression factor we need to achieve to return compressed rather than raw data
      • compressMinSizeBytes

        public int compressMinSizeBytes()
        Returns the minimal data size required to perform compression
      • compress

        public Compressor.Compression compress​(CompressionType requestedCompression,
                                               byte[] data,
                                               java.util.Optional<java.lang.Integer> uncompressedSize)
        Compresses some data
        Parameters:
        requestedCompression - the desired compression type, which will be used if the data is deemed suitable. Not all the existing types are actually supported.
        data - the data to compress. This array is only read by this method.
        uncompressedSize - uncompressedSize the size in bytes of the data array. If this is not present, it is assumed that the size is the same as the data array size, i.e that it is completely filled with uncompressed data.
        Returns:
        the compression result
        Throws:
        java.lang.IllegalArgumentException - if the compression type is not supported
      • compress

        public Compressor.Compression compress​(byte[] data,
                                               int uncompressedSize)
        Compresses some data using the compression type of this compressor
      • compress

        public Compressor.Compression compress​(byte[] data)
        Compresses some data using the compression type of this compressor
      • decompress

        public byte[] decompress​(CompressionType compression,
                                 byte[] compressedData,
                                 int compressedDataOffset,
                                 int expectedUncompressedSize,
                                 java.util.Optional<java.lang.Integer> expectedCompressedSize)
        Decompresses some data
        Parameters:
        compression - the compression type used
        compressedData - the compressed data. This array is only read by this method.
        compressedDataOffset - the offset in the compressed data at which to start decompression
        expectedUncompressedSize - the uncompressed size in bytes of this data
        expectedCompressedSize - the expected compressed size of the data in bytes, optionally for validation with LZ4.
        Returns:
        the uncompressed data, of the given size
        Throws:
        java.lang.IllegalArgumentException - if the compression type is not supported
        java.lang.IllegalStateException - if the expected compressed size is non-empty and specifies a different size than the actual size
      • decompress

        public byte[] decompress​(byte[] compressedData,
                                 CompressionType compressionType,
                                 int uncompressedSize)
        Decompresses some data
      • compressUnconditionally

        public byte[] compressUnconditionally​(byte[] input)
      • compressUnconditionally

        public byte[] compressUnconditionally​(java.nio.ByteBuffer input)
      • decompressUnconditionally

        public void decompressUnconditionally​(java.nio.ByteBuffer input,
                                              java.nio.ByteBuffer output)
      • decompressUnconditionally

        public byte[] decompressUnconditionally​(byte[] input,
                                                int srcOffset,
                                                int uncompressedLen)
      • warmup

        public long warmup​(double seconds)