- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
Zstd
PanamaZstdInputStream and any
other consumer that needs incremental ZSTD_decompressStream semantics: refill an
input chunk, call decompress(byte[], int, int, byte[], int, int), read lastSrcPos() / lastDstPos() to
advance cursors, loop while the hint return is positive (more input wanted), and observe a
zero return when the current frame finished.
Bounds are validated Java-side; error returns from libzstd are translated to
IllegalArgumentException carrying the ZSTD_getErrorName string. All hot-path
state (the two ZSTD_inBuffer/ZSTD_outBuffer struct holders, the native context
handle) lives inside the binding — every decompress(byte[], int, int, byte[], int, int) call is allocation-free.
Not thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Idempotent — frees the nativeZSTD_DStreamand the cached struct holders.longdecompress(byte[] dst, int dstPos, int dstLen, byte[] src, int srcPos, int srcLen) Feedsrc[srcPos..srcLen)into the decoder and write decompressed bytes intodst[dstPos..dstLen).intOutput position after the most recentdecompress(byte[], int, int, byte[], int, int)— an absolute index into thedstarray that was passed to that call.intInput position after the most recentdecompress(byte[], int, int, byte[], int, int)— an absolute index into thesrcarray that was passed to that call.
-
Method Details
-
decompress
public long decompress(byte[] dst, int dstPos, int dstLen, byte[] src, int srcPos, int srcLen) Feedsrc[srcPos..srcLen)into the decoder and write decompressed bytes intodst[dstPos..dstLen). Returns the libzstd hint:0means the current frame finished decoding (the decoder is implicitly reset for the next concatenated frame, if any), a positive return is libzstd's best guess for the amount of additional input it would like to see next, and a zstd-side error is translated toIllegalArgumentException.After return, the caller reads
lastSrcPos()/lastDstPos()to learn how far the input/output cursors advanced — these are absolute offsets within the supplied arrays, not deltas.Chunking contract. Callers must pass at most
Zstd.dStreamInSize()bytes of input per call (srcLen - srcPos <= dStreamInSize()). Larger slices raiseIllegalArgumentExceptionfrom the binding — the binding hard-fails rather than silently consuming a prefix because partial consumption is easy to overlook at call sites.PanamaZstdInputStreamcaches the recommended size in astatic finaland refills upstream in chunks of that size. Output may be any size; the binding internally caps each call atZstd.dStreamOutSize()and the caller's outer loop drives subsequent calls as needed. -
lastDstPos
public int lastDstPos()Output position after the most recentdecompress(byte[], int, int, byte[], int, int)— an absolute index into thedstarray that was passed to that call. -
lastSrcPos
public int lastSrcPos()Input position after the most recentdecompress(byte[], int, int, byte[], int, int)— an absolute index into thesrcarray that was passed to that call. -
close
public void close()Idempotent — frees the nativeZSTD_DStreamand the cached struct holders.- Specified by:
closein interfaceAutoCloseable
-