public class LZ4CompressorWithLength
extends java.lang.Object
LZ4DecompressorWithLength
and is NOT compatible with any other
decompressors in lz4-java or any other lz4 tools. This class deliberately
does not extend LZ4Compressor
because they are not interchangable.Constructor and Description |
---|
LZ4CompressorWithLength(LZ4Compressor compressor)
Creates a new compressor that includes the length of the original
decompressed data in the output compressed data.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
compress(byte[] src)
Convenience method, equivalent to calling
compress(src, 0, src.length) . |
int |
compress(byte[] src,
byte[] dest)
Convenience method, equivalent to calling
compress(src, 0, src.length, dest, 0) . |
byte[] |
compress(byte[] src,
int srcOff,
int srcLen)
Convenience method which returns
src[srcOff:srcOff+srcLen]
compressed. |
int |
compress(byte[] src,
int srcOff,
int srcLen,
byte[] dest,
int destOff)
Convenience method, equivalent to calling
compress(src, srcOff, srcLen, dest, destOff, dest.length - destOff) . |
int |
compress(byte[] src,
int srcOff,
int srcLen,
byte[] dest,
int destOff,
int maxDestLen)
Compresses
src[srcOff:srcOff+srcLen] into
dest[destOff:destOff+maxDestLen] and returns the compressed
length. |
void |
compress(java.nio.ByteBuffer src,
java.nio.ByteBuffer dest)
Compresses
src into dest . |
int |
compress(java.nio.ByteBuffer src,
int srcOff,
int srcLen,
java.nio.ByteBuffer dest,
int destOff,
int maxDestLen)
Compresses
src[srcOff:srcOff+srcLen] into
dest[destOff:destOff+maxDestLen] and returns the compressed
length. |
int |
maxCompressedLength(int length)
Returns the maximum compressed length for an input of size
length . |
public LZ4CompressorWithLength(LZ4Compressor compressor)
compressor
- compressor to usepublic int maxCompressedLength(int length)
length
.length
- the input size in bytespublic byte[] compress(byte[] src)
compress(src, 0, src.length)
.src
- the source datapublic byte[] compress(byte[] src, int srcOff, int srcLen)
src[srcOff:srcOff+srcLen]
compressed.
Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to compress into, and then needs to resize this buffer to the actual compressed length.
Here is how this method is implemented:
final int maxCompressedLength = maxCompressedLength(srcLen); final byte[] compressed = new byte[maxCompressedLength]; final int compressedLength = compress(src, srcOff, srcLen, compressed, 0); return Arrays.copyOf(compressed, compressedLength);
src
- the source datasrcOff
- the start offset in srcsrcLen
- the number of bytes to compresspublic int compress(byte[] src, byte[] dest)
compress(src, 0, src.length, dest, 0)
.src
- the source datadest
- the destination bufferLZ4Exception
- if dest is too smallpublic int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff)
compress(src, srcOff, srcLen, dest, destOff, dest.length - destOff)
.src
- the source datasrcOff
- the start offset in srcsrcLen
- the number of bytes to compressdest
- the destination bufferdestOff
- the start offset in destLZ4Exception
- if dest is too smallpublic int compress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen)
src[srcOff:srcOff+srcLen]
into
dest[destOff:destOff+maxDestLen]
and returns the compressed
length.
This method will throw a LZ4Exception
if this compressor is unable
to compress the input into less than maxDestLen
bytes. To
prevent this exception to be thrown, you should make sure that
maxDestLen >= maxCompressedLength(srcLen)
.src
- the source datasrcOff
- the start offset in srcsrcLen
- the number of bytes to compressdest
- the destination bufferdestOff
- the start offset in destmaxDestLen
- the maximum number of bytes to write in destLZ4Exception
- if maxDestLen is too smallpublic void compress(java.nio.ByteBuffer src, java.nio.ByteBuffer dest)
src
into dest
. Calling this method
will update the positions of both ByteBuffer
s.src
- the source datadest
- the destination bufferLZ4Exception
- if dest is too smallpublic int compress(java.nio.ByteBuffer src, int srcOff, int srcLen, java.nio.ByteBuffer dest, int destOff, int maxDestLen)
src[srcOff:srcOff+srcLen]
into
dest[destOff:destOff+maxDestLen]
and returns the compressed
length.
This method will throw a LZ4Exception
if this compressor is unable
to compress the input into less than maxDestLen
bytes. To
prevent this exception to be thrown, you should make sure that
maxDestLen >= maxCompressedLength(srcLen)
.
ByteBuffer
positions remain unchanged.src
- the source datasrcOff
- the start offset in srcsrcLen
- the number of bytes to compressdest
- the destination bufferdestOff
- the start offset in destmaxDestLen
- the maximum number of bytes to write in destLZ4Exception
- if maxDestLen is too small