Package net.jpountz.lz4
Class LZ4SafeDecompressor
java.lang.Object
net.jpountz.lz4.LZ4SafeDecompressor
- All Implemented Interfaces:
LZ4UnknownSizeDecompressor
LZ4 decompressor that requires the size of the compressed data to be known.
Implementations of this class are usually a little slower than those of
LZ4FastDecompressor but do not require the size of the original data to
be known.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal intdecompress(byte[] src, byte[] dest) Convenience method, equivalent to callingdecompress(src, 0, src.length, dest, 0)final byte[]decompress(byte[] src, int maxDestLen) Convenience method, equivalent to callingdecompress(src, 0, src.length, maxDestLen).final intdecompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) Convenience method, equivalent to callingdecompress(src, srcOff, srcLen, dest, destOff, dest.length - destOff).abstract intdecompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) Decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:destOff+maxDestLen]and returns the number of decompressed bytes written intodest.final byte[]decompress(byte[] src, int srcOff, int srcLen, int maxDestLen) Convenience method which returnssrc[srcOff:srcOff+srcLen]decompressed.abstract intdecompress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff, int maxDestLen) Decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:destOff+maxDestLen]and returns the number of decompressed bytes written intodest.final voiddecompress(ByteBuffer src, ByteBuffer dest) Decompressessrcintodest.toString()
-
Constructor Details
-
LZ4SafeDecompressor
public LZ4SafeDecompressor()
-
-
Method Details
-
decompress
public abstract int decompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen) Decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:destOff+maxDestLen]and returns the number of decompressed bytes written intodest.- Specified by:
decompressin interfaceLZ4UnknownSizeDecompressor- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed datadest- the destination buffer to store the decompressed datadestOff- the start offset in destmaxDestLen- the maximum number of bytes to write in dest- Returns:
- the original input size
- Throws:
LZ4Exception- if maxDestLen is too small
-
decompress
public abstract int decompress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff, int maxDestLen) Decompressessrc[srcOff:srcOff+srcLen]intodest[destOff:destOff+maxDestLen]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 datadest- the destination buffer to store the decompressed datadestOff- the start offset in destmaxDestLen- the maximum number of bytes to write in dest- Returns:
- the original input size
- Throws:
LZ4Exception- if maxDestLen is too small
-
decompress
public final int decompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff) Convenience method, equivalent to callingdecompress(src, srcOff, srcLen, dest, destOff, dest.length - destOff).- Specified by:
decompressin interfaceLZ4UnknownSizeDecompressor- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed datadest- the destination buffer to store the decompressed datadestOff- the start offset in dest- Returns:
- the original input size
- Throws:
LZ4Exception- if dest is too small
-
decompress
public final int decompress(byte[] src, byte[] dest) Convenience method, equivalent to callingdecompress(src, 0, src.length, dest, 0)- Parameters:
src- the compressed datadest- the destination buffer to store the decompressed data- Returns:
- the original input size
- Throws:
LZ4Exception- if dest is too small
-
decompress
public final byte[] decompress(byte[] src, int srcOff, int srcLen, int maxDestLen) Convenience method which returnssrc[srcOff:srcOff+srcLen]decompressed.Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into, and then needs to resize this buffer to the actual decompressed length.
Here is how this method is implemented:
byte[] decompressed = new byte[maxDestLen]; final int decompressedLength = decompress(src, srcOff, srcLen, decompressed, 0, maxDestLen); if (decompressedLength != decompressed.length) { decompressed = Arrays.copyOf(decompressed, decompressedLength); } return decompressed;- Parameters:
src- the compressed datasrcOff- the start offset in srcsrcLen- the exact size of the compressed datamaxDestLen- the maximum number of bytes to write in dest- Returns:
- the decompressed data
- Throws:
LZ4Exception- if maxDestLen is too small
-
decompress
public final byte[] decompress(byte[] src, int maxDestLen) Convenience method, equivalent to callingdecompress(src, 0, src.length, maxDestLen).- Parameters:
src- the compressed datamaxDestLen- the maximum number of bytes to write in dest- Returns:
- the decompressed data
- Throws:
LZ4Exception- if maxDestLen is too small
-
decompress
Decompressessrcintodest.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- Throws:
LZ4Exception- if dest is too small
-
toString
-