Package com.yahoo.compress
Class Compressor
java.lang.Object
com.yahoo.compress.Compressor
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
-
Constructor Summary
ConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptioncompress
(byte[] data) Compresses some data using the compression type of this compressorcompress
(byte[] data, int uncompressedSize) Compresses some data using the compression type of this compressorcompress
(CompressionType requestedCompression, byte[] data) Compresses some data using the requested compression typecompress
(CompressionType requestedCompression, byte[] data, int offset, int len) compress
(CompressionType requestedCompression, byte[] data, Optional<Integer> uncompressedSize) Compresses some datadouble
Returns the compression factor we need to achieve to return compressed rather than raw dataint
Returns the minimal data size required to perform compressionbyte[]
compressUnconditionally
(byte[] input) byte[]
byte[]
decompress
(byte[] compressedData, CompressionType compressionType, int uncompressedSize) Decompresses some databyte[]
decompress
(CompressionType compression, byte[] compressedData, int compressedDataOffset, int expectedUncompressedSize, Optional<Integer> expectedCompressedSize) Decompresses some databyte[]
decompress
(Compressor.Compression compression) Decompresses some databyte[]
decompressUnconditionally
(byte[] input, int srcOffset, int uncompressedLen) void
decompressUnconditionally
(ByteBuffer input, ByteBuffer output) int
level()
Returns the compression level this will use - a number between 0 and 9 where higher means more compressiontype()
Returns the default compression type used by thislong
warmup
(double seconds)
-
Constructor Details
-
Compressor
public Compressor()Creates a compressor with default settings. -
Compressor
Creates a compressor with a default compression type. -
Compressor
-
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 Details
-
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, Optional<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:
IllegalArgumentException
- if the compression type is not supported
-
compress
public Compressor.Compression compress(CompressionType requestedCompression, byte[] data, int offset, int len) -
compress
Compresses some data using the requested compression type -
compress
Compresses some data using the compression type of this compressor -
compress
Compresses some data using the compression type of this compressor -
decompress
public byte[] decompress(CompressionType compression, byte[] compressedData, int compressedDataOffset, int expectedUncompressedSize, Optional<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:
IllegalArgumentException
- if the compression type is not supportedIllegalStateException
- 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
Decompresses some data -
compressUnconditionally
public byte[] compressUnconditionally(byte[] input) -
compressUnconditionally
-
decompressUnconditionally
-
decompressUnconditionally
public byte[] decompressUnconditionally(byte[] input, int srcOffset, int uncompressedLen) -
warmup
public long warmup(double seconds)
-