Top Description Fields Constructors Methods
org.lwjgl.util.lz4

public Class LZ4Frame

extends Object
Class Inheritance
Imports
javax.annotation.*, java.nio.*, org.lwjgl.*, org.lwjgl.system.*

Native bindings to the frame API of LZ4.

LZ4F is a stand-alone API to create LZ4-compressed frames conformant with specification v1.6.1. It also offers streaming capabilities. lz4.h is not required when using lz4frame.h, except to get constant such as VERSION_NUMBER.

Field Summary

Modifier and TypeField and Description
public static final int
LZ4F_BLOCK_CHECKSUM_SIZE

Size in bytes of a block checksum footer in little-endian format.

public static final int
LZ4F_BLOCK_HEADER_SIZE

Size in bytes of a block header in little-endian format.

public static final int
public static final int
LZ4F_blockIndependent

LZ4F_blockMode_t

Linked blocks sharply reduce inefficiencies when using small blocks, they compress better.

public static final int
LZ4F_blockLinked

LZ4F_blockMode_t

Linked blocks sharply reduce inefficiencies when using small blocks, they compress better.

public static final int
LZ4F_CONTENT_CHECKSUM_SIZE

Size in bytes of the content checksum.

public static final int
public static final int
LZ4F_default

LZ4F_blockSizeID_t

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns.

public static final LZ4FCustomMem
LZ4F_defaultCMem

This constant defers to stdlib's functions

public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
LZ4F_ERROR_GENERIC

Error code.

public static final int
public static final int
public static final int
public static final int
LZ4F_ERROR_maxCode

Error code.

public static final int
public static final int
public static final int
public static final int
public static final int
LZ4F_frame

LZ4F_frameType_t Enum values:

public static final int
LZ4F_HEADER_SIZE_MAX

Maximum header size.

public static final int
LZ4F_HEADER_SIZE_MIN

Minimum header size.

public static final int
public static final int
public static final int
LZ4F_max1MB

LZ4F_blockSizeID_t

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns.

public static final int
LZ4F_max256KB

LZ4F_blockSizeID_t

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns.

public static final int
LZ4F_max4MB

LZ4F_blockSizeID_t

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns.

public static final int
LZ4F_max64KB

LZ4F_blockSizeID_t

The larger the block size, the (slightly) better the compression ratio, though there are diminishing returns.

public static final int
public static final int
public static final int
public static final int
LZ4F_OK_NoError

Error code.

public static final int
LZ4F_skippableFrame

LZ4F_frameType_t Enum values:

public static final int
LZ4F_VERSION

Version number.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

number of bytes written into dstBuffer for the header or an error code (which can be tested using isError)
LZ4F_compressBegin
(long cctx, ByteBuffer dstBuffer, LZ4FPreferences
optional: you can provide NULL as argument, all preferences will then be set to default
prefsPtr
)

Will write the frame header into dstBuffer.

public static long

Returns:

number of bytes written into dstBuffer for the header, or an error code (which can be tested using isError)
LZ4F_compressBegin_usingCDict
(long cctx, ByteBuffer dstBuffer, long cdict, LZ4FPreferences
optional: you may provide NULL as argument, however, it's the only way to provide dictID in the frame header
prefsPtr
)

Inits streaming dictionary compression, and writes the frame header into dstBuffer.

public static long
LZ4F_compressBound(long srcSize, LZ4FPreferences
optional: when NULL is provided, preferences will be set to cover worst case scenario
prefsPtr
)

Provides minimum dstCapacity required to guarantee success of compressUpdate, given a srcSize and preferences, for a worst case scenario.

public static long

Returns:

nb of bytes written into dstBuffer, necessarily ≥ 4 (endMark), or an error code if it fails (which can be tested using isError).

A successful call to compressEnd makes cctx available again for another compression task.

LZ4F_compressEnd
(long cctx, ByteBuffer dstBuffer, LZ4FCompressOptions
optional: NULL can be provided, in which case all options will be set to default
cOptPtr
)

To properly finish an LZ4 frame, invoke compressEnd.

public static long

Returns:

number of bytes written into dstBuffer or an error code if it fails (can be tested using isError)
LZ4F_compressFrame
(ByteBuffer dstBuffer, ByteBuffer srcBuffer, LZ4FPreferences preferencesPtr)

Compress an entire srcBuffer into a valid LZ4 frame.

public static long

Returns:

number of bytes written into dstBuffer or an error code if it fails (can be tested using isError)
LZ4F_compressFrame_usingCDict
(long
must point to a context created by createCompressionContext.
cctx
,
ByteBuffer dst, ByteBuffer src, long
if NULL, compress without a dictionary
cdict
,
LZ4FPreferences
optional: you may provide NULL as argument, but it's not recommended, as it's the only way to provide dictID in the frame header
preferencesPtr
)

Compress an entire srcBuffer into a valid LZ4 frame using a digested Dictionary.

public static long
LZ4F_compressFrameBound(long srcSize, LZ4FPreferences preferencesPtr)

Returns the maximum possible size of a frame compressed with compressFrame given srcSize content and preferences.

public static native int
public static long

Returns:

number of bytes written into dstBuffer (it can be zero, meaning input data was just buffered) or an error code if it fails (which can be tested using isError)
LZ4F_compressUpdate
(long cctx, ByteBuffer dstBuffer, ByteBuffer srcBuffer, LZ4FCompressOptions
optional: NULL can be provided, in which case all options are set to default
cOptPtr
)

LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary.

public static long
LZ4F_createCDict(ByteBuffer dictBuffer)

When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once.

public static long
LZ4F_createCDict_advanced(LZ4FCustomMem customMem, ByteBuffer dictBuffer)

createCDict with custom allocation/free functions.

public static long

Returns:

if != zero, context creation failed.
LZ4F_createCompressionContext
(PointerBuffer
MUST be != NULL
cctxPtr
,
int
MUST be VERSION. It is intended to track potential version mismatch, notably when using DLL. Must be:
VERSION
version
)

The first thing to do is to create a compressionContext object, which will keep track of operation state during streaming compression.

public static long
LZ4F_createCompressionContext_advanced(LZ4FCustomMem customMem, int version)

createCompressionContext with custom allocation/free functions.

public static long

Returns:

an errorCode, which can be tested using isError
LZ4F_createDecompressionContext
(PointerBuffer
MUST be valid
dctxPtr
,
int
must be:
VERSION
version
)

Create an LZ4F_dctx object, to track all decompression operations.

public static long
LZ4F_createDecompressionContext_advanced(LZ4FCustomMem customMem, int version)

createDecompressionContext with custom allocation/free functions.

public static long

Returns:

a hint of how many srcSize bytes LZ4F_decompress() expects for next call.

Schematically, it's the size of the current (or remaining) compressed block + header of next block. Respecting the hint provides some small speed benefit, because it skips intermediate buffers. This is just a hint though, it's always possible to provide any srcSize.

When a frame is fully decoded, return will be 0 (no more data expected). When provided with more bytes than necessary to decode a frame, LZ4F_decompress() will stop reading exactly at end of current frame, and return 0.

If decompression failed, return is an error code, which can be tested using isError. After a decompression error, the dctx context is not resumable. Use resetDecompressionContext to return to clean state.

LZ4F_decompress
(long dctx, ByteBuffer dstBuffer, PointerBuffer dstSizePtr, ByteBuffer srcBuffer, PointerBuffer srcSizePtr, LZ4FDecompressOptions dOptPtr)

Call this function repetitively to regenerate data compressed in srcBuffer.

public static long
LZ4F_decompress_usingDict(long dctxPtr, ByteBuffer dstBuffer, PointerBuffer dstSizePtr, ByteBuffer srcBuffer, PointerBuffer srcSizePtr, ByteBuffer dict, LZ4FDecompressOptions decompressOptionsPtr)

Same as decompress, using a predefined dictionary.

private static LZ4FCustomMem
public static long

Returns:

nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx) or an error code if it fails (which can be tested using isError)
LZ4F_flush
(long cctx, ByteBuffer dstBuffer, LZ4FCompressOptions
optional: it's possible to provide NULL, all options will be set to default
cOptPtr
)

When data must be generated and sent immediately, without waiting for a block to be completely filled, it's possible to call flush.

public static void
LZ4F_freeCDict(long CDict)

public static native long
LZ4F_freeCompressionContext(long cctx)

Frees an LZ4F_cctx object.

public static long

Returns:

an errorCode, which can be tested using isError.

Result of LZ4F_freeDecompressionContext() indicates current state of decompressionContext when being released. That is, it should be == 0 if decompression has been completed fully and correctly.

LZ4F_freeDecompressionContext
(long dctx)

Frees an LZ4F_dctx object.

public static native long
LZ4F_getBlockSize(int blockSizeID)

Return, in scalar format (size_t), the maximum block size associated with blockSizeID.

public static native int
LZ4F_getErrorCode(long functionResult)

public static String
LZ4F_getErrorName(long code)

Return error code string; for debugging.

public static long

Returns:

an hint about how many srcSize bytes LZ4F_decompress() expects for next call, or an error code which can be tested using LZ4F_isError()
LZ4F_getFrameInfo
(long dctx, LZ4FFrameInfo frameInfoPtr, ByteBuffer srcBuffer, PointerBuffer srcSizePtr)

This function extracts frame parameters (max blockSize, dictID, etc.).

public static native int
public static long

Returns:

size of frame header or an error code, which can be tested using isError
LZ4F_headerSize
(ByteBuffer src)

Provide the header size of a frame starting at src.

public static boolean
LZ4F_isError(long code)

Tells when a function result is an error code.

public static void
LZ4F_resetDecompressionContext(long dctx)

In case of an error, the context is left in "undefined" state.

public static long

Returns:

number of bytes written into dstBuffer (it can be zero, meaning input data was just buffered), or an error code if it fails (which can be tested using isError)"
LZ4F_uncompressedUpdate
(long cctx, ByteBuffer dstBuffer, ByteBuffer srcBuffer, LZ4FCompressOptions
optional : NULL can be provided, in which case all options are set to default
cOptPtr
)

Can be called repetitively to add as much data uncompressed data as necessary.

public static native long
nLZ4F_compressBegin(long cctx, long dstBuffer, long
must be ≥ HEADER_SIZE_MAX bytes
dstCapacity
,
long prefsPtr)

Unsafe version of: compressBegin

public static native long
nLZ4F_compressBegin_usingCDict(long cctx, long dstBuffer, long dstCapacity, long cdict, long prefsPtr)

Unsafe version of: compressBegin_usingCDict

public static native long
nLZ4F_compressBound(long srcSize, long prefsPtr)

Unsafe version of: compressBound

public static native long
nLZ4F_compressEnd(long cctx, long dstBuffer, long dstCapacity, long cOptPtr)

Unsafe version of: compressEnd

public static native long
nLZ4F_compressFrame(long dstBuffer, long
MUST be ≥ compressFrameBound(srcSize, preferencesPtr)
dstCapacity
,
long srcBuffer, long srcSize, long preferencesPtr)

Unsafe version of: compressFrame

public static native long
nLZ4F_compressFrame_usingCDict(long cctx, long dst, long dstCapacity, long src, long srcSize, long cdict, long preferencesPtr)

Unsafe version of: compressFrame_usingCDict

public static native long
nLZ4F_compressFrameBound(long srcSize, long preferencesPtr)

Unsafe version of: compressFrameBound

public static native long
nLZ4F_compressUpdate(long cctx, long dstBuffer, long dstCapacity, long srcBuffer, long srcSize, long cOptPtr)

Unsafe version of: compressUpdate

public static native long
nLZ4F_createCDict(long dictBuffer, long dictSize)

Unsafe version of: createCDict

public static native long
nLZ4F_createCDict_advanced(long customMem, long dictBuffer, long dictSize)

Unsafe version of: createCDict_advanced

public static native long
nLZ4F_createCompressionContext(long cctxPtr, int version)

Unsafe version of: createCompressionContext

public static native long
nLZ4F_createCompressionContext_advanced(long customMem, int version)

Unsafe version of: createCompressionContext_advanced

public static native long
nLZ4F_createDecompressionContext(long dctxPtr, int version)

Unsafe version of: createDecompressionContext

public static native long
public static native long
nLZ4F_decompress(long dctx, long dstBuffer, long dstSizePtr, long srcBuffer, long srcSizePtr, long dOptPtr)

Unsafe version of: decompress

public static native long
nLZ4F_decompress_usingDict(long dctxPtr, long dstBuffer, long dstSizePtr, long srcBuffer, long srcSizePtr, long dict, long dictSize, long decompressOptionsPtr)

Unsafe version of: decompress_usingDict

private static native void
nLZ4F_defaultCMem(long __result)

public static native long
nLZ4F_flush(long cctx, long dstBuffer, long
must be large enough to ensure the operation will be successful
dstCapacity
,
long cOptPtr)

Unsafe version of: flush

public static native void
nLZ4F_freeCDict(long CDict)

public static native long
public static native long
nLZ4F_getErrorName(long code)

Unsafe version of: getErrorName

public static native long
nLZ4F_getFrameInfo(long dctx, long frameInfoPtr, long srcBuffer, long srcSizePtr)

Unsafe version of: getFrameInfo

public static native long
nLZ4F_headerSize(long src, long
must be ≥ MIN_SIZE_TO_KNOW_HEADER_LENGTH, which is enough to decode the header length
srcSize
)

Unsafe version of: headerSize

public static native int
nLZ4F_isError(long code)

Unsafe version of: isError

public static native void
public static native long
nLZ4F_uncompressedUpdate(long cctx, long dstBuffer, long dstCapacity, long srcBuffer, long srcSize, long cOptPtr)

Unsafe version of: uncompressedUpdate

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait