Class ZstdDecompressor

java.lang.Object
io.github.mahmoudimus.zstd.ZstdDecompressor

public final class ZstdDecompressor extends Object
Decodes Zstandard data (RFC 8878). Instances are immutable and thread-safe; each stream they create is not.

 byte[] plain = ZstdDecompressor.create().decompress(compressed);
 try (InputStream in = ZstdDecompressor.create().inputStream(socketIn)) { ... }
 

Concatenated frames are decoded in order and skippable frames are ignored. Memory is bounded by ZstdDecompressor.Builder.maxWindowSize: frames that need a larger history are rejected, and the history buffer only grows as output is produced.

  • Field Details

    • DEFAULT_MAX_WINDOW_SIZE

      public static final int DEFAULT_MAX_WINDOW_SIZE
      The default window limit, 128 MiB: what the reference decoder accepts by default.
      See Also:
  • Method Details

    • create

      public static ZstdDecompressor create()
      Returns a decompressor with default settings.
      Returns:
      the shared, immutable default decompressor
    • builder

      public static ZstdDecompressor.Builder builder()
      Creates a builder initialized with the default settings.
      Returns:
      a new builder
    • inputStream

      public ZstdInputStream inputStream(InputStream in)
      Creates a stream of the data decoded from in.
      Parameters:
      in - compressed input; closing the returned stream also closes this input
      Returns:
      a new decompression stream using this decompressor's settings
    • decompress

      public byte[] decompress(byte[] data) throws ZstdException
      Decodes all of data.
      Parameters:
      data - compressed frames
      Returns:
      the concatenated decompressed contents
      Throws:
      ZstdException - if the data is invalid or exceeds the decoder's limits
    • decompress

      public byte[] decompress(byte[] data, int maxOutputSize) throws ZstdException
      Decodes all of data, failing if the output would exceed maxOutputSize bytes.
      Parameters:
      data - compressed frames
      maxOutputSize - maximum decompressed output size in bytes
      Returns:
      the concatenated decompressed contents
      Throws:
      ZstdException - if the data is invalid or exceeds the output or decoder limits