java.lang.Object
org.elasticsearch.nativeaccess.Zstd.DStream
All Implemented Interfaces:
AutoCloseable
Enclosing class:
Zstd

public final class Zstd.DStream extends Object implements AutoCloseable
Streaming-mode zstd decompression resource. Backs 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 Details

    • decompress

      public long decompress(byte[] dst, int dstPos, int dstLen, byte[] src, int srcPos, int srcLen)
      Feed src[srcPos..srcLen) into the decoder and write decompressed bytes into dst[dstPos..dstLen). Returns the libzstd hint: 0 means 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 to IllegalArgumentException.

      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 raise IllegalArgumentException from the binding — the binding hard-fails rather than silently consuming a prefix because partial consumption is easy to overlook at call sites. PanamaZstdInputStream caches the recommended size in a static final and refills upstream in chunks of that size. Output may be any size; the binding internally caps each call at Zstd.dStreamOutSize() and the caller's outer loop drives subsequent calls as needed.

    • lastDstPos

      public int lastDstPos()
      Output position after the most recent decompress(byte[], int, int, byte[], int, int) — an absolute index into the dst array that was passed to that call.
    • lastSrcPos

      public int lastSrcPos()
      Input position after the most recent decompress(byte[], int, int, byte[], int, int) — an absolute index into the src array that was passed to that call.
    • close

      public void close()
      Idempotent — frees the native ZSTD_DStream and the cached struct holders.
      Specified by:
      close in interface AutoCloseable