Package com.github.luben.zstd
Class ZstdDecompressCtx
- java.lang.Object
-
- com.github.luben.zstd.AutoCloseBase
-
- com.github.luben.zstd.ZstdDecompressCtx
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ZstdDecompressCtx extends AutoCloseBase
-
-
Field Summary
Fields Modifier and Type Field Description private ZstdDictDecompressdecompression_dictprivate longnativePtr
-
Constructor Summary
Constructors Constructor Description ZstdDecompressCtx()Create a context for faster compress operations One such context is required for each thread - put this in a ThreadLocal.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intdecompress(byte[] dst, byte[] src)byte[]decompress(byte[] src, int originalSize)Decompress datajava.nio.ByteBufferdecompress(java.nio.ByteBuffer srcBuf, int originalSize)intdecompress(java.nio.ByteBuffer dstBuf, java.nio.ByteBuffer srcBuf)Decompresses buffer 'srcBuff' into buffer 'dstBuff' using this ZstdDecompressCtx.intdecompressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize)Decompresses byte array 'srcBuff' into byte array 'dstBuff' using this ZstdDecompressCtx.private static longdecompressByteArray0(long nativePtr, byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)intdecompressDirectByteBuffer(java.nio.ByteBuffer dstBuff, int dstOffset, int dstSize, java.nio.ByteBuffer srcBuff, int srcOffset, int srcSize)Decompresses buffer 'srcBuff' into buffer 'dstBuff' using this ZstdDecompressCtx.private static longdecompressDirectByteBuffer0(long nativePtr, java.nio.ByteBuffer dst, int dstOffset, int dstSize, java.nio.ByteBuffer src, int srcOffset, int srcSize)booleandecompressDirectByteBufferStream(java.nio.ByteBuffer dst, java.nio.ByteBuffer src)Decompress as much of thesrcByteBufferinto thedstByteBufferas possible.private static longdecompressDirectByteBufferStream0(long nativePtr, java.nio.ByteBuffer dst, int dstOffset, int dstSize, java.nio.ByteBuffer src, int srcOffset, int srcSize)4 pieces of information are packed into the return value of this method, which must be treated as an unsigned long.(package private) voiddoClose()private voidensureOpen()private static voidfree(long nativePtr)private static longinit()private static longloadDDict0(long nativePtr, byte[] dict)private static longloadDDictFast0(long nativePtr, ZstdDictDecompress dict)ZstdDecompressCtxloadDict(byte[] dict)Load decompression dictionary.ZstdDecompressCtxloadDict(ZstdDictDecompress dict)Load decompression dictionaryvoidreset()Clear all state and parameters from the decompression context.private static voidreset0(long nativePtr)ZstdDecompressCtxsetMagicless(boolean magiclessFlag)Enable or disable magicless frames-
Methods inherited from class com.github.luben.zstd.AutoCloseBase
acquireSharedLock, close, releaseSharedLock, storeFence
-
-
-
-
Field Detail
-
nativePtr
private long nativePtr
-
decompression_dict
private ZstdDictDecompress decompression_dict
-
-
Method Detail
-
init
private static long init()
-
free
private static void free(long nativePtr)
-
doClose
void doClose()
- Specified by:
doClosein classAutoCloseBase
-
setMagicless
public ZstdDecompressCtx setMagicless(boolean magiclessFlag)
Enable or disable magicless frames- Parameters:
magiclessFlag- A 32-bits checksum of content is written at end of frame, default: false
-
loadDict
public ZstdDecompressCtx loadDict(ZstdDictDecompress dict)
Load decompression dictionary- Parameters:
dict- the dictionary or `null` to remove loaded dictionary
-
loadDDictFast0
private static long loadDDictFast0(long nativePtr, ZstdDictDecompress dict)
-
loadDict
public ZstdDecompressCtx loadDict(byte[] dict)
Load decompression dictionary.- Parameters:
dict- the dictionary or `null` to remove loaded dictionary
-
loadDDict0
private static long loadDDict0(long nativePtr, byte[] dict)
-
reset
public void reset()
Clear all state and parameters from the decompression context. This leaves the object in a state identical to a newly created decompression context.
-
reset0
private static void reset0(long nativePtr)
-
ensureOpen
private void ensureOpen()
-
decompressDirectByteBufferStream
public boolean decompressDirectByteBufferStream(java.nio.ByteBuffer dst, java.nio.ByteBuffer src)Decompress as much of thesrcByteBufferinto thedstByteBufferas possible.- Parameters:
dst- destination of uncompressed datasrc- buffer to decompress- Returns:
- true if all state has been flushed from internal buffers
-
decompressDirectByteBufferStream0
private static long decompressDirectByteBufferStream0(long nativePtr, java.nio.ByteBuffer dst, int dstOffset, int dstSize, java.nio.ByteBuffer src, int srcOffset, int srcSize)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.
-
decompressDirectByteBuffer
public int decompressDirectByteBuffer(java.nio.ByteBuffer dstBuff, int dstOffset, int dstSize, java.nio.ByteBuffer srcBuff, int srcOffset, int srcSize)Decompresses buffer 'srcBuff' into buffer 'dstBuff' using this ZstdDecompressCtx. Destination buffer should be sized to be larger of equal to the originalSize. 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- the destination buffer - must be directdstOffset- the start offset of 'dstBuff'dstSize- the size of 'dstBuff'srcBuff- the source buffer - must be directsrcOffset- the start offset of 'srcBuff'srcSize- the size of 'srcBuff'- Returns:
- the number of bytes decompressed into destination buffer (originalSize)
-
decompressDirectByteBuffer0
private static long decompressDirectByteBuffer0(long nativePtr, java.nio.ByteBuffer dst, int dstOffset, int dstSize, java.nio.ByteBuffer src, int srcOffset, int srcSize)
-
decompressByteArray
public int decompressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[] srcBuff, int srcOffset, int srcSize)Decompresses byte array 'srcBuff' into byte array 'dstBuff' using this ZstdDecompressCtx. Destination buffer should be sized to be larger of equal to the originalSize.- Parameters:
dstBuff- the destination bufferdstOffset- the start offset of 'dstBuff'dstSize- the size of 'dstBuff'srcBuff- the source buffersrcOffset- the start offset of 'srcBuff'srcSize- the size of 'srcBuff'- Returns:
- the number of bytes decompressed into destination buffer (originalSize)
-
decompressByteArray0
private static long decompressByteArray0(long nativePtr, byte[] dst, int dstOffset, int dstSize, byte[] src, int srcOffset, int srcSize)
-
decompress
public int decompress(java.nio.ByteBuffer dstBuf, java.nio.ByteBuffer srcBuf) throws ZstdExceptionDecompresses buffer 'srcBuff' into buffer 'dstBuff' using this ZstdDecompressCtx. Destination buffer should be sized to be larger of equal to the originalSize.- Parameters:
dstBuf- the destination buffer - must be direct. It is assumed that the `position()` of this buffer marks the offset at which the decompressed data are to be written, and that the `limit()` of this buffer is the maximum decompressed data size to allow.When this method returns successfully, its `position()` will be set to its current `position()` plus the decompressed size of the data.
srcBuf- the source buffer - must be direct. It is assumed that the `position()` of this buffer marks the beginning of the compressed data to be decompressed, 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:
- the size of the decompressed data.
- Throws:
ZstdException
-
decompress
public java.nio.ByteBuffer decompress(java.nio.ByteBuffer srcBuf, int originalSize) throws ZstdException- Throws:
ZstdException
-
decompress
public int decompress(byte[] dst, byte[] src)
-
decompress
public byte[] decompress(byte[] src, int originalSize) throws ZstdExceptionDecompress data- Parameters:
src- the source bufferoriginalSize- the maximum size of the uncompressed data. If originaSize is greater than the actuall uncompressed size, additional memory copy going to happen. If originalSize is smaller than the uncompressed size, ZstdExeption will be thrown.- Returns:
- byte array with the decompressed data
- Throws:
ZstdException
-
-