Top Fields Constructors Methods
com.github.luben.zstd

public Class ZstdCompressCtx

extends AutoCloseBase
Class Inheritance
Imports
com.github.luben.zstd.util.Native, com.github.luben.zstd.ZstdDictCompress, java.nio.ByteBuffer, java.util.Arrays

Field Summary

Modifier and TypeField and Description
private ZstdDictCompress
private long
private SequenceProducer
private long

Constructor Summary

AccessConstructor and Description
public
ZstdCompressCtx()

Create a context for faster compress operations One such context is required for each thread - put this in a ThreadLocal.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the size of the compressed data
compress
(ByteBuffer
the destination buffer - must be direct. It is assumed that the `position()` of this buffer marks the offset at which the compressed data are to be written, and that the `limit()` of this buffer is the maximum compressed data size to allow.

When this method returns successfully, its `position()` will be set to its current `position()` plus the compressed size of the data.

dstBuf
,
ByteBuffer
the source buffer - must be direct. It is assumed that the `position()` of this buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

When this method returns successfully, its `position()` will be set to the initial `limit()`.

srcBuf
)

Compresses the data in buffer 'srcBuf'

public ByteBuffer

Returns:

A newly allocated direct ByteBuffer containing the compressed data.
compress
(ByteBuffer
the source buffer - must be direct. It is assumed that the `position()` of the buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

When this method returns successfully, its `position()` will be set to its initial `limit()`.

srcBuf
)

Compresses the data in buffer 'srcBuf'

public int
compress(byte[] dst, byte[] src)

public byte[]
compress(byte[] src)

public int

Returns:

the number of bytes written into buffer 'dstBuff'.
compressByteArray
(byte[]
the destination buffer (byte array)
dstBuff
,
int
the start offset of 'dstBuff'
dstOffset
,
int
the size of 'dstBuff' (after 'dstOffset')
dstSize
,
byte[]
the source buffer (byte array)
srcBuff
,
int
the start offset of 'srcBuff'
srcOffset
,
int
the length of 'srcBuff' (after 'srcOffset')
srcSize
)

Compresses byte array 'srcBuff' into byte array 'dstBuff' reusing this ZstdCompressCtx.

private static native long
compressByteArray0(long ptr, byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)

public int

Returns:

the number of bytes written into buffer 'dstBuff'.
compressDirectByteBuffer
(ByteBuffer
the destination buffer - must be direct
dstBuff
,
int
the start offset of 'dstBuff'
dstOffset
,
int
the size of 'dstBuff' (after 'dstOffset')
dstSize
,
ByteBuffer
the source buffer - must be direct
srcBuff
,
int
the start offset of 'srcBuff'
srcOffset
,
int
the length of 'srcBuff' (after 'srcOffset')
srcSize
)

Compresses buffer 'srcBuff' into buffer 'dstBuff' reusing this ZstdCompressCtx.

private static native long
compressDirectByteBuffer0(long ptr, ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize)

public boolean

Returns:

true if all state has been flushed from internal buffers
compressDirectByteBufferStream
(ByteBuffer
destination of compressed data
dst
,
ByteBuffer
buffer to compress
src
,
EndDirective
directive for handling the end of the stream
endOp
)

Compress as much of the src ByteBuffer into the dst ByteBuffer as possible.

private static native long
compressDirectByteBufferStream0(long ptr, ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcSize, int srcOffset, int endOp)

4 pieces of information are packed into the return value of this method, which must be treated as an unsigned long.

pack-priv void
private void
private static native void
free(long ptr)

public ZstdFrameProgression
getFrameProgression()

Tells how much data has been ingested (read from input), consumed (input actually compressed) and produced (output) for current frame.

private static native ZstdFrameProgression
pack-priv long
private static native long
init()

private native long
loadCDict0(long ptr, byte[] dict)

private native long
public ZstdCompressCtx
loadDict(ZstdDictCompress
the dictionary or `null` to remove loaded dictionary
dict
)

Load compression dictionary to be used for subsequently compressed frames.

public ZstdCompressCtx
loadDict(byte[]
the dictionary or `null` to remove loaded dictionary
dict
)

Load compression dictionary to be used for subsequently compressed frames.

public ZstdCompressCtx
registerSequenceProducer(SequenceProducer
the user-defined SequenceProducer to register.
producer
)

Register an external sequence producer

public void
reset()

Clear all state and parameters from the compression context.

private static native long
reset0(long ptr)

public ZstdCompressCtx
setChainLog(int chainLog)

public ZstdCompressCtx
setChecksum(boolean
A 32-bits checksum of content is written at end of frame, default: false
checksumFlag
)

Enable or disable compression checksums

private static native void
setChecksum0(long ptr, boolean checksumFlag)

public ZstdCompressCtx
setContentSize(boolean
Content size will be written into frame header _whenever known_, default: true
contentSizeFlag
)

Enable or disable content size

private static native void
setContentSize0(long ptr, boolean contentSizeFlag)

public ZstdCompressCtx
setDictID(boolean
When applicable, dictionary's ID is written into frame header, default: true
dictIDFlag
)

Enable or disable dictID

private static native void
setDictID0(long ptr, boolean dictIDFlag)

public ZstdCompressCtx
setEnableLongDistanceMatching(Zstd.ParamSwitch
whether to enable long-distance matching.
enableLDM
)

Enable or disable long-distance matching.

public ZstdCompressCtx
setHashLog(int hashLog)

public ZstdCompressCtx
setJobSize(int jobSize)

public ZstdCompressCtx
setLevel(int
compression level, default: Zstd#defaultCompressionLevel()
level
)

Set compression level

private static native void
setLevel0(long ptr, int level)

public ZstdCompressCtx
setLong(int
Maximum allowed back-reference distance, expressed as power of 2. This will set a memory budget for streaming decompression, with larger values requiring more memory and typically compressing more. Must be clamped between 10 and 32/64 but values greater than 27 may not be decompressable in all context as they require more memory. 0 disables LDM.
windowLog
)

Enable or disable LongDistanceMatching and set the window size

public ZstdCompressCtx
setMagicless(boolean
A 32-bits magic number is written at start of frame, default: false
magiclessFlag
)

Enable or disable magicless frames

public ZstdCompressCtx
setMinMatch(int minMatch)

public ZstdCompressCtx
setOverlapLog(int overlapLog)

public void
setPledgedSrcSize(long srcSize)

Promise to compress a certain number of source bytes.

private static native long
setPledgedSrcSize0(long ptr, long srcSize)

public ZstdCompressCtx
setSearchForExternalRepcodes(Zstd.ParamSwitch
whether to search for repcodes
searchRepcodes
)

Set whether to search external sequences for repeated offsets that can be encoded as repcodes.

public ZstdCompressCtx
setSearchLog(int searchLog)

public ZstdCompressCtx
setSequenceProducerFallback(boolean
fall back to the default internal sequence producer if an external sequence producer returns an error code, default: false
fallbackFlag
)

Enable or disable sequence producer fallback

public ZstdCompressCtx
setStrategy(int strategy)

public ZstdCompressCtx
setTargetLength(int targetLength)

public ZstdCompressCtx
setValidateSequences(Zstd.ParamSwitch
whether to enable sequence validation
validateSequences
)

Enable or disable sequence validation.

public ZstdCompressCtx
setWindowLog(int windowLog)

public ZstdCompressCtx
setWorkers(int workers)

Inherited from com.github.luben.zstd.AutoCloseBase:
acquireSharedLockclosereleaseSharedLockstoreFence

Field Detail

compression_dictback to summary
private ZstdDictCompress compression_dict
nativePtrback to summary
private long nativePtr
seqprodback to summary
private SequenceProducer seqprod
seqprod_stateback to summary
private long seqprod_state

Constructor Detail

ZstdCompressCtxback to summary
public ZstdCompressCtx()

Create a context for faster compress operations One such context is required for each thread - put this in a ThreadLocal.

Method Detail

compressback to summary
public int compress(ByteBuffer dstBuf, ByteBuffer srcBuf)

Compresses the data in buffer 'srcBuf'

Parameters
dstBuf:ByteBuffer

the destination buffer - must be direct. It is assumed that the `position()` of this buffer marks the offset at which the compressed data are to be written, and that the `limit()` of this buffer is the maximum compressed data size to allow.

When this method returns successfully, its `position()` will be set to its current `position()` plus the compressed size of the data.

srcBuf:ByteBuffer

the source buffer - must be direct. It is assumed that the `position()` of this buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

When this method returns successfully, its `position()` will be set to the initial `limit()`.

Returns:int

the size of the compressed data

compressback to summary
public ByteBuffer compress(ByteBuffer srcBuf) throws ZstdException

Compresses the data in buffer 'srcBuf'

Parameters
srcBuf:ByteBuffer

the source buffer - must be direct. It is assumed that the `position()` of the buffer marks the beginning of the uncompressed data to be compressed, and that the `limit()` of this buffer marks its end.

When this method returns successfully, its `position()` will be set to its initial `limit()`.

Returns:ByteBuffer

A newly allocated direct ByteBuffer containing the compressed data.

compressback to summary
public int compress(byte[] dst, byte[] src)
compressback to summary
public byte[] compress(byte[] src)
compressByteArrayback to summary
public int compressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize)

Compresses byte array 'srcBuff' into byte array 'dstBuff' reusing this ZstdCompressCtx. Destination buffer should be sized to handle worst cases situations (input data not compressible). Worst case size evaluation is provided by function ZSTD_compressBound().

Parameters
dstBuff:byte[]

the destination buffer (byte array)

dstOffset:int

the start offset of 'dstBuff'

dstSize:int

the size of 'dstBuff' (after 'dstOffset')

srcBuff:byte[]

the source buffer (byte array)

srcOffset:int

the start offset of 'srcBuff'

srcSize:int

the length of 'srcBuff' (after 'srcOffset')

Returns:int

the number of bytes written into buffer 'dstBuff'.

compressByteArray0back to summary
private static native long compressByteArray0(long ptr, byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)
compressDirectByteBufferback to summary
public int compressDirectByteBuffer(ByteBuffer dstBuff, int dstOffset, int dstSize, ByteBuffer srcBuff, int srcOffset, int srcSize)

Compresses buffer 'srcBuff' into buffer 'dstBuff' reusing this ZstdCompressCtx. Destination buffer should be sized to handle worst cases situations (input data not compressible). Worst case size evaluation is provided by function ZSTD_compressBound(). This is a low-level function that does not take into account or affect the `limit` or `position` of source or destination buffers.

Parameters
dstBuff:ByteBuffer

the destination buffer - must be direct

dstOffset:int

the start offset of 'dstBuff'

dstSize:int

the size of 'dstBuff' (after 'dstOffset')

srcBuff:ByteBuffer

the source buffer - must be direct

srcOffset:int

the start offset of 'srcBuff'

srcSize:int

the length of 'srcBuff' (after 'srcOffset')

Returns:int

the number of bytes written into buffer 'dstBuff'.

compressDirectByteBuffer0back to summary
private static native long compressDirectByteBuffer0(long ptr, ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcOffset, int srcSize)
compressDirectByteBufferStreamback to summary
public boolean compressDirectByteBufferStream(ByteBuffer dst, ByteBuffer src, EndDirective endOp)

Compress as much of the src ByteBuffer into the dst ByteBuffer as possible.

Parameters
dst:ByteBuffer

destination of compressed data

src:ByteBuffer

buffer to compress

endOp:EndDirective

directive for handling the end of the stream

Returns:boolean

true if all state has been flushed from internal buffers

compressDirectByteBufferStream0back to summary
private static native long compressDirectByteBufferStream0(long ptr, ByteBuffer dst, int dstOffset, int dstSize, ByteBuffer src, int srcSize, int srcOffset, int endOp)

4 pieces of information are packed into the return value of this method, which must be treated as an unsigned long. The highest bit is set if all data has been flushed from internal buffers. The next 31 bits are the new position of the destination buffer. The next bit is set if an error occurred. If an error occurred, the lowest 31 bits encode a zstd error code. Otherwise, the lowest 31 bits are the new position of the source buffer.

doCloseback to summary
pack-priv void doClose()

Implements abstract com.github.luben.zstd.AutoCloseBase.doClose.

ensureOpenback to summary
private void ensureOpen()
freeback to summary
private static native void free(long ptr)
getFrameProgressionback to summary
public ZstdFrameProgression getFrameProgression()

Tells how much data has been ingested (read from input), consumed (input actually compressed) and produced (output) for current frame.

getFrameProgression0back to summary
private static native ZstdFrameProgression getFrameProgression0(long ptr)
getNativePtrback to summary
pack-priv long getNativePtr()
initback to summary
private static native long init()
loadCDict0back to summary
private native long loadCDict0(long ptr, byte[] dict)
loadCDictFast0back to summary
private native long loadCDictFast0(long ptr, ZstdDictCompress dict)
loadDictback to summary
public ZstdCompressCtx loadDict(ZstdDictCompress dict)

Load compression dictionary to be used for subsequently compressed frames.

Parameters
dict:ZstdDictCompress

the dictionary or `null` to remove loaded dictionary

loadDictback to summary
public ZstdCompressCtx loadDict(byte[] dict)

Load compression dictionary to be used for subsequently compressed frames.

Parameters
dict:byte[]

the dictionary or `null` to remove loaded dictionary

registerSequenceProducerback to summary
public ZstdCompressCtx registerSequenceProducer(SequenceProducer producer)

Register an external sequence producer

Parameters
producer:SequenceProducer

the user-defined SequenceProducer to register.

resetback to summary
public void reset()

Clear all state and parameters from the compression context. This leaves the object in a state identical to a newly created compression context.

reset0back to summary
private static native long reset0(long ptr)
setChainLogback to summary
public ZstdCompressCtx setChainLog(int chainLog)
setChecksumback to summary
public ZstdCompressCtx setChecksum(boolean checksumFlag)

Enable or disable compression checksums

Parameters
checksumFlag:boolean

A 32-bits checksum of content is written at end of frame, default: false

setChecksum0back to summary
private static native void setChecksum0(long ptr, boolean checksumFlag)
setContentSizeback to summary
public ZstdCompressCtx setContentSize(boolean contentSizeFlag)

Enable or disable content size

Parameters
contentSizeFlag:boolean

Content size will be written into frame header _whenever known_, default: true

setContentSize0back to summary
private static native void setContentSize0(long ptr, boolean contentSizeFlag)
setDictIDback to summary
public ZstdCompressCtx setDictID(boolean dictIDFlag)

Enable or disable dictID

Parameters
dictIDFlag:boolean

When applicable, dictionary's ID is written into frame header, default: true

setDictID0back to summary
private static native void setDictID0(long ptr, boolean dictIDFlag)
setEnableLongDistanceMatchingback to summary
public ZstdCompressCtx setEnableLongDistanceMatching(Zstd.ParamSwitch enableLDM)

Enable or disable long-distance matching.

Parameters
enableLDM:Zstd.ParamSwitch

whether to enable long-distance matching.

setHashLogback to summary
public ZstdCompressCtx setHashLog(int hashLog)
setJobSizeback to summary
public ZstdCompressCtx setJobSize(int jobSize)
setLevelback to summary
public ZstdCompressCtx setLevel(int level)

Set compression level

Parameters
level:int

compression level, default: Zstd#defaultCompressionLevel()

setLevel0back to summary
private static native void setLevel0(long ptr, int level)
setLongback to summary
public ZstdCompressCtx setLong(int windowLog)

Enable or disable LongDistanceMatching and set the window size

Parameters
windowLog:int

Maximum allowed back-reference distance, expressed as power of 2. This will set a memory budget for streaming decompression, with larger values requiring more memory and typically compressing more. Must be clamped between 10 and 32/64 but values greater than 27 may not be decompressable in all context as they require more memory. 0 disables LDM.

setMagiclessback to summary
public ZstdCompressCtx setMagicless(boolean magiclessFlag)

Enable or disable magicless frames

Parameters
magiclessFlag:boolean

A 32-bits magic number is written at start of frame, default: false

setMinMatchback to summary
public ZstdCompressCtx setMinMatch(int minMatch)
setOverlapLogback to summary
public ZstdCompressCtx setOverlapLog(int overlapLog)
setPledgedSrcSizeback to summary
public void setPledgedSrcSize(long srcSize)

Promise to compress a certain number of source bytes. Knowing the number of bytes to compress up front helps to choose proper compression settings and size internal buffers. Additionally, the pledged size is stored in the header of the output stream, allowing decompressors to know how much uncompressed data to expect. Attempting to compress more or less than the pledged size will result in an error.

setPledgedSrcSize0back to summary
private static native long setPledgedSrcSize0(long ptr, long srcSize)
setSearchForExternalRepcodesback to summary
public ZstdCompressCtx setSearchForExternalRepcodes(Zstd.ParamSwitch searchRepcodes)

Set whether to search external sequences for repeated offsets that can be encoded as repcodes.

Parameters
searchRepcodes:Zstd.ParamSwitch

whether to search for repcodes

setSearchLogback to summary
public ZstdCompressCtx setSearchLog(int searchLog)
setSequenceProducerFallbackback to summary
public ZstdCompressCtx setSequenceProducerFallback(boolean fallbackFlag)

Enable or disable sequence producer fallback

Parameters
fallbackFlag:boolean

fall back to the default internal sequence producer if an external sequence producer returns an error code, default: false

setStrategyback to summary
public ZstdCompressCtx setStrategy(int strategy)
setTargetLengthback to summary
public ZstdCompressCtx setTargetLength(int targetLength)
setValidateSequencesback to summary
public ZstdCompressCtx setValidateSequences(Zstd.ParamSwitch validateSequences)

Enable or disable sequence validation. Useful for the sequence-level API and with external sequence producers.

Parameters
validateSequences:Zstd.ParamSwitch

whether to enable sequence validation

setWindowLogback to summary
public ZstdCompressCtx setWindowLog(int windowLog)
setWorkersback to summary
public ZstdCompressCtx setWorkers(int workers)