Class ZstdInputStreamNoFinalizer

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.github.luben.zstd.ZstdInputStreamNoFinalizer
All Implemented Interfaces:
Closeable, AutoCloseable

public class ZstdInputStreamNoFinalizer extends FilterInputStream
InputStream filter that decompresses the data provided by the underlying InputStream using Zstd compression. It does not support mark/reset methods. It also does not have finalizer, so if you rely on finalizers to clean the native memory and release buffers use `ZstdInputStream` instead.
  • Constructor Details

    • ZstdInputStreamNoFinalizer

      public ZstdInputStreamNoFinalizer(@NotNull @NotNull InputStream inStream) throws IOException
      create a new decompressing InputStream
      Parameters:
      inStream - the stream to wrap
      Throws:
      IOException
    • ZstdInputStreamNoFinalizer

      public ZstdInputStreamNoFinalizer(@NotNull @NotNull InputStream inStream, @NotNull @NotNull BufferPool bufferPool) throws IOException
      create a new decompressing InputStream
      Parameters:
      inStream - the stream to wrap
      bufferPool - the pool to fetch and return buffers
      Throws:
      IOException
  • Method Details

    • recommendedDInSize

      public static long recommendedDInSize()
    • recommendedDOutSize

      public static long recommendedDOutSize()
    • setContinuous

      @NotNull public @NotNull ZstdInputStreamNoFinalizer setContinuous(boolean b)
      Don't break on unfinished frames Use case: decompressing files that are not yet finished writing and compressing
    • getContinuous

      public boolean getContinuous()
    • setDict

      @NotNull public @NotNull ZstdInputStreamNoFinalizer setDict(byte @NotNull [] dict) throws IOException
      Throws:
      IOException
    • setDict

      @NotNull public @NotNull ZstdInputStreamNoFinalizer setDict(@NotNull @NotNull ZstdDictDecompress dict) throws IOException
      Throws:
      IOException
    • setLongMax

      @NotNull public @NotNull ZstdInputStreamNoFinalizer setLongMax(int windowLogMax) throws IOException
      Throws:
      IOException
    • setRefMultipleDDicts

      @NotNull public @NotNull ZstdInputStreamNoFinalizer setRefMultipleDDicts(boolean useMultiple) throws IOException
      Throws:
      IOException
    • read

      public int read(byte @NotNull [] dst, int offset, int len) throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read() throws IOException
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • available

      public int available() throws IOException
      Overrides:
      available in class FilterInputStream
      Throws:
      IOException
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class FilterInputStream
    • skip

      public long skip(long numBytes) throws IOException
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException
    • resetSession

      public InputStream resetSession(@NotNull @NotNull InputStream newInput) throws IOException
      Reset the decompression stream to read from a new InputStream. This reuses the existing native ZSTD_DStream context, including its internal window buffer and any previously loaded dictionary. The native context is reset via ZSTD_DCtx_reset with ZSTD_reset_session_only, which resets the session state without freeing or reallocating the window buffer and without clearing loaded dictionaries or parameters. If the next frame's window size fits within the existing buffer, no native memory allocation occurs at all. Previously configured settings such as setContinuous(boolean) and loaded dictionaries are preserved across the reset. The previous InputStream is not closed; the caller is responsible for its lifecycle. This is intended for pooling: instead of creating a new ZstdInputStreamNoFinalizer (which calls ZSTD_createDStream + malloc) for each compressed stream and then closing it (which calls ZSTD_freeDStream + free), callers can keep a single instance and call reset() with each new input stream.
      Parameters:
      newInput - the new compressed input stream to decompress
      Returns:
      the old input stream
      Throws:
      IOException - if the stream has been closed or the native reset fails
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterInputStream
      Throws:
      IOException