These functions compress data in successive blocks of any size, using previous blocks as dictionary, to improve compression ratio. One key assumption
is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks. There is an exception for ring buffers, which can be
smaller than 64 KB. Ring-buffer scenario is automatically detected and handled within compress_HC_continue.
Before starting compression, state must be allocated and properly initialized. createStreamHC does both, though compression level is set to
CLEVEL_DEFAULT.
Selecting the compression level can be done with resetStreamHC_fast (starts a new stream) setCompressionLevel (anytime, between blocks in the
same stream) (experimental). LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once, which is
automatically the case when state is created using LZ4_createStreamHC().
After reset, a first "fictional block" can be designated as initial dictionary, using loadDictHC (Optional).
Invoke compress_HC_continue to compress each successive block. The number of blocks is unlimited. Previous input blocks, including initial
dictionary when present, must remain accessible and unmodified during compression.
It's allowed to update compression level anytime between blocks, using LZ4_setCompressionLevel() (experimental).
dst buffer should be sized to handle worst case scenarios (see compressBound, it ensures compression success). In case of failure, the API
does not guarantee recovery, so the state must be reset. To ensure compression success whenever dst buffer size cannot be made ≥
LZ4_compressBound(), consider using compress_HC_continue_destSize.
Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks, it's possible to copy the last blocks into a
more stable memory space, using saveDictHC. Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into
safeBuffer (≤ 64 KB)
After completing a streaming compression, it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state, just by
resetting it, using LZ4_resetStreamHC_fast().
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | LZ4HC_CLEVEL_DEFAULT
Compression level. |
| public static final int | LZ4HC_CLEVEL_MAX
Compression level. |
| public static final int | LZ4HC_CLEVEL_MIN
Compression level. |
| public static final int | LZ4HC_CLEVEL_OPT_MIN
Compression level. |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static void | LZ4_attach_HC_dictionary(long working_stream, long dictionary_stream)
This is an experimental API that allows for the efficient use of a static dictionary many times. |
| public static int | Returns: the number of bytes written intodst or 0 if compression failsmust be already allocated dst, int compressionLevel)Compress data from |
| public static int | |
| public static int | Returns: the number of bytes written intodst (necessarily ≤ targetDstSize) or 0 if compression failson success, srcSizePtr)*srcSizePtr will be updated to indicate how much bytes were read from src. Note that this function may not consume the
entire input.Similar to |
| public static int | Returns: the number of bytes written intodst (necessarily ≤ targetDstSize) or 0 if compression failson success, srcSizePtr, int compressionLevel)*srcSizePtr is updated to indicate how much bytes were read from srcWill compress as much data as possible from |
| public static int | LZ4_compress_HC_extStateHC(ByteBuffer state, ByteBuffer src, ByteBuffer dst, int compressionLevel)
Same as |
| public static int | LZ4_compress_HC_extStateHC_fastReset(ByteBuffer state, ByteBuffer src, ByteBuffer dst, int compressionLevel)
A variant of |
| public static native long | |
| public static void | LZ4_favorDecompressionSpeed(long LZ4_streamHCPtr, boolean favor)
Parser will favor decompression speed over compression ratio. |
| public static int | |
| public static long | LZ4_initStreamHC(ByteBuffer buffer)
Required before first use of a statically allocated |
| public static int | |
| public static void | LZ4_resetStreamHC_fast(long LZ4_streamHCPtr, int compressionLevel)
When an |
| public static int | |
| public static void | LZ4_setCompressionLevel(long LZ4_streamHCPtr, int compressionLevel)
It's possible to change compression level between successive invocations of |
| public static native int | |
| public static native void | nLZ4_attach_HC_dictionary(long working_stream, long dictionary_stream)
Unsafe version of: |
| public static native int | nLZ4_compress_HC(long src, long dst, int
max supported value is srcSize, int dstCapacity, int compressionLevel)MAX_INPUT_SIZEUnsafe version of: |
| public static native int | |
| public static native int | nLZ4_compress_HC_continue_destSize(long streamHCPtr, long src, long dst, long
on success, srcSizePtr, int targetDstSize)*srcSizePtr will be updated to indicate how much bytes were read from src. Note that this function may not consume the
entire input.Unsafe version of: |
| public static native int | nLZ4_compress_HC_destSize(long stateHC, long src, long dst, long
on success, srcSizePtr, int targetDstSize, int compressionLevel)*srcSizePtr is updated to indicate how much bytes were read from srcUnsafe version of: |
| public static native int | nLZ4_compress_HC_extStateHC(long state, long src, long dst, int srcSize, int maxDstSize, int compressionLevel)
Unsafe version of: |
| public static native int | nLZ4_compress_HC_extStateHC_fastReset(long state, long src, long dst, int srcSize, int dstCapacity, int compressionLevel)
Unsafe version of: |
| public static native void | nLZ4_favorDecompressionSpeed(long LZ4_streamHCPtr, int favor)
Unsafe version of: |
| public static native int | |
| public static native long | |
| public static native int | |
| public static native void | nLZ4_resetStreamHC_fast(long LZ4_streamHCPtr, int compressionLevel)
Unsafe version of: |
| public static native int | |
| public static native void | nLZ4_setCompressionLevel(long LZ4_streamHCPtr, int compressionLevel)
Unsafe version of: |
| LZ4_STREAMHC_MINSIZE | back to summary |
|---|---|
| public static final int LZ4_STREAMHC_MINSIZE | |
| LZ4HC_CLEVEL_DEFAULT | back to summary |
|---|---|
| public static final int LZ4HC_CLEVEL_DEFAULT Compression level. | |
| LZ4HC_CLEVEL_MAX | back to summary |
|---|---|
| public static final int LZ4HC_CLEVEL_MAX Compression level. | |
| LZ4HC_CLEVEL_MIN | back to summary |
|---|---|
| public static final int LZ4HC_CLEVEL_MIN Compression level. | |
| LZ4HC_CLEVEL_OPT_MIN | back to summary |
|---|---|
| public static final int LZ4HC_CLEVEL_OPT_MIN Compression level. | |
| LZ4HC_DICTIONARY_LOGSIZE | back to summary |
|---|---|
| public static final int LZ4HC_DICTIONARY_LOGSIZE | |
| LZ4HC_HASH_LOG | back to summary |
|---|---|
| public static final int LZ4HC_HASH_LOG | |
| LZ4HC_HASH_MASK | back to summary |
|---|---|
| public static final int LZ4HC_HASH_MASK | |
| LZ4HC_HASHTABLESIZE | back to summary |
|---|---|
| public static final int LZ4HC_HASHTABLESIZE | |
| LZ4HC_MAXD | back to summary |
|---|---|
| public static final int LZ4HC_MAXD | |
| LZ4HC_MAXD_MASK | back to summary |
|---|---|
| public static final int LZ4HC_MAXD_MASK | |
| LZ4HC | back to summary |
|---|---|
| protected LZ4HC() | |
| LZ4_attach_HC_dictionary | back to summary |
|---|---|
| public static void LZ4_attach_HC_dictionary(long working_stream, long dictionary_stream) This is an experimental API that allows for the efficient use of a static dictionary many times. Rather than re-loading the dictionary buffer into a working context before each compression, or copying a pre-loaded dictionary's
Several assumptions are made about the state of the dictionary stream. Currently, only streams which have been prepared by Alternatively, the provided dictionary stream pointer may be A dictionary should only be attached to a stream without any history (i.e., a stream that has just been reset). The dictionary will remain attached to the working stream only for the current stream session. Calls to | |
| LZ4_compress_HC | back to summary |
|---|---|
| public static int LZ4_compress_HC(ByteBuffer src, ByteBuffer dst, int compressionLevel) Compress data from Compression is guaranteed to succeed if
| |
| LZ4_compress_HC_continue | back to summary |
|---|---|
| public static int LZ4_compress_HC_continue(long streamHCPtr, ByteBuffer src, ByteBuffer dst) | |
| LZ4_compress_HC_continue_destSize | back to summary |
|---|---|
| public static int LZ4_compress_HC_continue_destSize(long streamHCPtr, ByteBuffer src, ByteBuffer dst, IntBuffer srcSizePtr) Similar to
| |
| LZ4_compress_HC_destSize | back to summary |
|---|---|
| public static int LZ4_compress_HC_destSize(ByteBuffer stateHC, ByteBuffer src, ByteBuffer dst, IntBuffer srcSizePtr, int compressionLevel) Will compress as much data as possible from
| |
| LZ4_compress_HC_extStateHC | back to summary |
|---|---|
| public static int LZ4_compress_HC_extStateHC(ByteBuffer state, ByteBuffer src, ByteBuffer dst, int compressionLevel) Same as
| |
| LZ4_compress_HC_extStateHC_fastReset | back to summary |
|---|---|
| public static int LZ4_compress_HC_extStateHC_fastReset(ByteBuffer state, ByteBuffer src, ByteBuffer dst, int compressionLevel) A variant of Using this variant avoids an expensive initialization step. It is only safe to call if the state buffer is known to be correctly initialized already
(see comment on | |
| LZ4_createStreamHC | back to summary |
|---|---|
| public static native long LZ4_createStreamHC() Creates memory for LZ4 HC streaming state. Newly created states are automatically initialized. A same state can be used multiple times consecutively, starting with
| |
| LZ4_favorDecompressionSpeed | back to summary |
|---|---|
| public static void LZ4_favorDecompressionSpeed(long LZ4_streamHCPtr, boolean favor) Parser will favor decompression speed over compression ratio. Only applicable to levels ≥
| |
| LZ4_freeStreamHC | back to summary |
|---|---|
| public static int LZ4_freeStreamHC(long streamHCPtr) Releases memory for LZ4 HC streaming state. | |
| LZ4_initStreamHC | back to summary |
|---|---|
| public static long LZ4_initStreamHC(ByteBuffer buffer) Required before first use of a statically allocated
| |
| LZ4_loadDictHC | back to summary |
|---|---|
| public static int LZ4_loadDictHC(long streamHCPtr, ByteBuffer dictionary) | |
| LZ4_resetStreamHC_fast | back to summary |
|---|---|
| public static void LZ4_resetStreamHC_fast(long LZ4_streamHCPtr, int compressionLevel) When an
Note A stream that was last used in a compression call that returned an error may be passed to this function. However, it will be fully reset, which will clear any existing history and settings from the context. | |
| LZ4_saveDictHC | back to summary |
|---|---|
| public static int LZ4_saveDictHC(long streamHCPtr, ByteBuffer safeBuffer) | |
| LZ4_setCompressionLevel | back to summary |
|---|---|
| public static void LZ4_setCompressionLevel(long LZ4_streamHCPtr, int compressionLevel) It's possible to change compression level between successive invocations of | |
| LZ4_sizeofStateHC | back to summary |
|---|---|
| public static native int LZ4_sizeofStateHC() | |
| nLZ4_attach_HC_dictionary | back to summary |
|---|---|
| public static native void nLZ4_attach_HC_dictionary(long working_stream, long dictionary_stream) Unsafe version of: | |
| nLZ4_compress_HC | back to summary |
|---|---|
| public static native int nLZ4_compress_HC(long src, long dst, int srcSize, int dstCapacity, int compressionLevel) Unsafe version of:
| |
| nLZ4_compress_HC_continue | back to summary |
|---|---|
| public static native int nLZ4_compress_HC_continue(long streamHCPtr, long src, long dst, int srcSize, int maxDstSize) | |
| nLZ4_compress_HC_continue_destSize | back to summary |
|---|---|
| public static native int nLZ4_compress_HC_continue_destSize(long streamHCPtr, long src, long dst, long srcSizePtr, int targetDstSize) Unsafe version of:
| |
| nLZ4_compress_HC_destSize | back to summary |
|---|---|
| public static native int nLZ4_compress_HC_destSize(long stateHC, long src, long dst, long srcSizePtr, int targetDstSize, int compressionLevel) Unsafe version of:
| |
| nLZ4_compress_HC_extStateHC | back to summary |
|---|---|
| public static native int nLZ4_compress_HC_extStateHC(long state, long src, long dst, int srcSize, int maxDstSize, int compressionLevel) Unsafe version of: | |
| nLZ4_compress_HC_extStateHC_fastReset | back to summary |
|---|---|
| public static native int nLZ4_compress_HC_extStateHC_fastReset(long state, long src, long dst, int srcSize, int dstCapacity, int compressionLevel) Unsafe version of: | |
| nLZ4_favorDecompressionSpeed | back to summary |
|---|---|
| public static native void nLZ4_favorDecompressionSpeed(long LZ4_streamHCPtr, int favor) Unsafe version of: | |
| nLZ4_freeStreamHC | back to summary |
|---|---|
| public static native int nLZ4_freeStreamHC(long streamHCPtr) Unsafe version of: | |
| nLZ4_initStreamHC | back to summary |
|---|---|
| public static native long nLZ4_initStreamHC(long buffer, long size) Unsafe version of: | |
| nLZ4_loadDictHC | back to summary |
|---|---|
| public static native int nLZ4_loadDictHC(long streamHCPtr, long dictionary, int dictSize) | |
| nLZ4_resetStreamHC_fast | back to summary |
|---|---|
| public static native void nLZ4_resetStreamHC_fast(long LZ4_streamHCPtr, int compressionLevel) Unsafe version of: | |
| nLZ4_saveDictHC | back to summary |
|---|---|
| public static native int nLZ4_saveDictHC(long streamHCPtr, long safeBuffer, int maxDictSize) | |
| nLZ4_setCompressionLevel | back to summary |
|---|---|
| public static native void nLZ4_setCompressionLevel(long LZ4_streamHCPtr, int compressionLevel) Unsafe version of: | |