Package net.jpountz.lz4
Class LZ4DecompressorWithLength
java.lang.Object
net.jpountz.lz4.LZ4DecompressorWithLength
Convenience class to decompress data compressed by
LZ4CompressorWithLength.
This decompressor is NOT compatible with any other compressors in lz4-java
or any other lz4 tools.
The user does not need to specify the length of the compressed data or
original data because the length of the original decompressed data is
included in the compressed data.-
Constructor Summary
ConstructorsConstructorDescriptionLZ4DecompressorWithLength(LZ4FastDecompressor fastDecompressor) Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength.LZ4DecompressorWithLength(LZ4FastDecompressor fastDecompressor, int maxDecompressedLength) Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength.LZ4DecompressorWithLength(LZ4SafeDecompressor safeDecompressor) Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength.LZ4DecompressorWithLength(LZ4SafeDecompressor safeDecompressor, int maxDecompressedLength) Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decompress(byte[] src) Convenience method, equivalent to callingdecompress(src, 0).intdecompress(byte[] src, byte[] dest) Convenience method, equivalent to callingdecompress(src, 0, dest, 0).byte[]decompress(byte[] src, int srcOff) Convenience method which returnssrc[srcOff:]decompressed whenLZ4FastDecompressorwas specified to the constructor, orsrc[srcOff:src.length]decompressed whenLZ4SafeDecompressorwas specified to the constructor.intdecompress(byte[] src, int srcOff, byte[] dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:src.length]intodest[destOff:]and returns the number of decompressed bytes written intodest.byte[]decompress(byte[] src, int srcOff, int srcLen) Convenience method which returnssrc[srcOff:]decompressed whenLZ4FastDecompressorwas specified to the constructor, orsrc[srcOff:srcOff+srcLen]decompressed whenLZ4SafeDecompressorwas specified to the constructor.intdecompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:]and returns the number of decompressed bytes written intodest.intdecompress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:]and returns the number of decompressed bytes written intodest.intdecompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:src.remaining()]intodest[destOff:]and returns the number of decompressed bytes written intodest.voiddecompress(ByteBuffer src, ByteBuffer dest) Decompressessrcintodest.static intgetDecompressedLength(byte[] src) Returns the decompressed length of compressed data insrc.static intgetDecompressedLength(byte[] src, int srcOff) Returns the decompressed length of compressed data insrc[srcOff:].static intReturns the decompressed length of compressed data insrc.static intgetDecompressedLength(ByteBuffer src, int srcOff) Returns the decompressed length of compressed data insrc[srcOff:].
-
Constructor Details
-
LZ4DecompressorWithLength
Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength. Methods that allocate their output buffer reject decompressed lengths greater than 64 MiB. Note that it is deprecated to use a JNI-binding instance ofLZ4FastDecompressor. Please seeLZ4Factory.nativeInstance()for details.- Parameters:
fastDecompressor- fast decompressor to use
-
LZ4DecompressorWithLength
Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength. Note that it is deprecated to use a JNI-binding instance ofLZ4FastDecompressor. Please seeLZ4Factory.nativeInstance()for details.- Parameters:
fastDecompressor- fast decompressor to usemaxDecompressedLength- maximum decompressed length for methods that allocate their output buffer- Throws:
IllegalArgumentException- if maxDecompressedLength is negative- Since:
- 1.11.2
-
LZ4DecompressorWithLength
Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength. Methods that allocate their output buffer reject decompressed lengths greater than 64 MiB.- Parameters:
safeDecompressor- safe decompressor to use
-
LZ4DecompressorWithLength
Creates a new decompressor to decompress data compressed byLZ4CompressorWithLength.- Parameters:
safeDecompressor- safe decompressor to usemaxDecompressedLength- maximum decompressed length for methods that allocate their output buffer- Throws:
IllegalArgumentException- if maxDecompressedLength is negative- Since:
- 1.11.2
-
-
Method Details
-
getDecompressedLength
public static int getDecompressedLength(byte[] src) Returns the decompressed length of compressed data insrc.- Parameters:
src- the compressed data- Returns:
- the decompressed length, without validating it against the compressed data
-
getDecompressedLength
public static int getDecompressedLength(byte[] src, int srcOff) Returns the decompressed length of compressed data insrc[srcOff:].- Parameters:
src- the compressed datasrcOff- the start offset in src- Returns:
- the decompressed length, without validating it against the compressed data
-
getDecompressedLength
Returns the decompressed length of compressed data insrc.- Parameters:
src- the compressed data- Returns:
- the decompressed length, without validating it against the compressed data
-
getDecompressedLength
Returns the decompressed length of compressed data insrc[srcOff:].- Parameters:
src- the compressed datasrcOff- the start offset in src- Returns:
- the decompressed length, without validating it against the compressed data
-
decompress
public int decompress(byte[] src, byte[] dest) Convenience method, equivalent to callingdecompress(src, 0, dest, 0).- Parameters:
src- the compressed datadest- the destination buffer to store the decompressed data- Returns:
- the number of bytes read to restore the original input
-
decompress
public int decompress(byte[] src, int srcOff, byte[] dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:src.length]intodest[destOff:]and returns the number of decompressed bytes written intodest.- Parameters:
src- the compressed datasrcOff- the start offset in srcdest- the destination buffer to store the decompressed datadestOff- the start offset in dest- Returns:
- the number of bytes read to restore the original input (when
LZ4FastDecompressoris used), or the number of decompressed bytes (whenLZ4SafeDecompressoris used)
-
decompress
public int decompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:]and returns the number of decompressed bytes written intodest.- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed data (ignored whenLZ4FastDecompressoris used)dest- the destination buffer to store the decompressed datadestOff- the start offset in dest- Returns:
- the number of bytes read to restore the original input (when
LZ4FastDecompressoris used), or the number of decompressed bytes (whenLZ4SafeDecompressoris used)
-
decompress
public byte[] decompress(byte[] src) Convenience method, equivalent to callingdecompress(src, 0).- Parameters:
src- the compressed data- Returns:
- the decompressed data
- Throws:
LZ4Exception- if the declared decompressed length is invalid or exceeds the configured maximum
-
decompress
public byte[] decompress(byte[] src, int srcOff) Convenience method which returnssrc[srcOff:]decompressed whenLZ4FastDecompressorwas specified to the constructor, orsrc[srcOff:src.length]decompressed whenLZ4SafeDecompressorwas specified to the constructor.Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into.
- Parameters:
src- the compressed datasrcOff- the start offset in src- Returns:
- the decompressed data
- Throws:
LZ4Exception- if the declared decompressed length is invalid or exceeds the configured maximum
-
decompress
public byte[] decompress(byte[] src, int srcOff, int srcLen) Convenience method which returnssrc[srcOff:]decompressed whenLZ4FastDecompressorwas specified to the constructor, orsrc[srcOff:srcOff+srcLen]decompressed whenLZ4SafeDecompressorwas specified to the constructor.Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into.
- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed data (ignored whenLZ4FastDecompressoris used)- Returns:
- the decompressed data
- Throws:
LZ4Exception- if the declared decompressed length is invalid or exceeds the configured maximum
-
decompress
Decompressessrcintodest. WhenLZ4SafeDecompressorwas specified to the constructor,src'sBuffer.remaining()must be exactly the size of the compressed data. This method moves the positions of the buffers.- Parameters:
src- the compressed datadest- the destination buffer to store the decompressed data
-
decompress
WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:src.remaining()]intodest[destOff:]and returns the number of decompressed bytes written intodest. The positions and limits of theByteBuffers remain unchanged.- Parameters:
src- the compressed datasrcOff- the start offset in srcdest- the destination buffer to store the decompressed datadestOff- the start offset in dest- Returns:
- the number of bytes read to restore the original input (when
LZ4FastDecompressoris used), or the number of decompressed bytes (whenLZ4SafeDecompressoris used)
-
decompress
WhenLZ4FastDecompressorwas specified to the constructor, decompressessrc[srcOff:]intodest[destOff:]and returns the number of bytes read fromsrc, and whenLZ4SafeDecompressorwas specified to the constructor, decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:]and returns the number of decompressed bytes written intodest. The positions and limits of theByteBuffers remain unchanged.- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed data (ignored whenLZ4FastDecompressoris used)dest- the destination buffer to store the decompressed datadestOff- the start offset in dest- Returns:
- the number of bytes read to restore the original input (when
LZ4FastDecompressoris used), or the number of decompressed bytes (whenLZ4SafeDecompressoris used)
-