public abstract class LZ4Compressor
extends java.lang.Object
Instances of this class are thread-safe.
| Constructor and Description |
|---|
LZ4Compressor() |
| 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). |
abstract 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. |
abstract 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. |
java.lang.String |
toString() |
public final int maxCompressedLength(int length)
length.length - the input size in bytespublic abstract 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 abstract 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 smallpublic final 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 final 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 final 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 final byte[] compress(byte[] src)
compress(src, 0, src.length).src - the source datapublic final void compress(java.nio.ByteBuffer src,
java.nio.ByteBuffer dest)
src into dest. Calling this method
will update the positions of both ByteBuffers.src - the source datadest - the destination bufferLZ4Exception - if dest is too smallpublic java.lang.String toString()
toString in class java.lang.Object