Package com.yahoo.compress
Class Compressor
- java.lang.Object
-
- com.yahoo.compress.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Compressor.Compression
-
Constructor Summary
Constructors Constructor Description Compressor()
Creates a compressor with default settings.Compressor(CompressionType type)
Creates a compressor with a default compression type.Compressor(CompressionType type, int level)
Compressor(CompressionType type, int level, double compressionThresholdFactor, int compressMinSizeBytes)
Creates a compressor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Compressor.Compression
compress(byte[] data)
Compresses some data using the compression type of this compressorCompressor.Compression
compress(byte[] data, int uncompressedSize)
Compresses some data using the compression type of this compressorCompressor.Compression
compress(CompressionType requestedCompression, byte[] data)
Compresses some data using the requested compression typeCompressor.Compression
compress(CompressionType requestedCompression, byte[] data, int offset, int len)
Compressor.Compression
compress(CompressionType requestedCompression, byte[] data, java.util.Optional<java.lang.Integer> uncompressedSize)
Compresses some datadouble
compressionThresholdFactor()
Returns the compression factor we need to achieve to return compressed rather than raw dataint
compressMinSizeBytes()
Returns the minimal data size required to perform compressionbyte[]
compressUnconditionally(byte[] input)
byte[]
compressUnconditionally(java.nio.ByteBuffer input)
byte[]
decompress(byte[] compressedData, CompressionType compressionType, int uncompressedSize)
Decompresses some databyte[]
decompress(CompressionType compression, byte[] compressedData, int compressedDataOffset, int expectedUncompressedSize, java.util.Optional<java.lang.Integer> expectedCompressedSize)
Decompresses some databyte[]
decompress(Compressor.Compression compression)
Decompresses some databyte[]
decompressUnconditionally(byte[] input, int srcOffset, int uncompressedLen)
void
decompressUnconditionally(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
int
level()
Returns the compression level this will use - a number between 0 and 9 where higher means more compressionCompressionType
type()
Returns the default compression type used by thislong
warmup(double seconds)
-
-
-
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)
-
Compressor
public Compressor(CompressionType type, int level, double compressionThresholdFactor, int compressMinSizeBytes)
Creates a compressor.- Parameters:
type
- the type of compression to use to compress datalevel
- a number between 0 and 9 where a higher value means more compressioncompressionThresholdFactor
- the compression factor we need to achieve to return the compressed data instead of raw datacompressMinSizeBytes
- 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(CompressionType requestedCompression, byte[] data, int offset, int len)
-
compress
public Compressor.Compression compress(CompressionType requestedCompression, byte[] data)
Compresses some data using the requested compression type
-
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 usedcompressedData
- the compressed data. This array is only read by this method.compressedDataOffset
- the offset in the compressed data at which to start decompressionexpectedUncompressedSize
- the uncompressed size in bytes of this dataexpectedCompressedSize
- 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 supportedjava.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
-
decompress
public byte[] decompress(Compressor.Compression compression)
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)
-
-