Package io.github.mahmoudimus.zstd
Class ZstdDecompressor
java.lang.Object
io.github.mahmoudimus.zstd.ZstdDecompressor
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default window limit, 128 MiB: what the reference decoder accepts by default. -
Method Summary
Modifier and TypeMethodDescriptionstatic ZstdDecompressor.Builderbuilder()Creates a builder initialized with the default settings.static ZstdDecompressorcreate()Returns a decompressor with default settings.byte[]decompress(byte[] data) Decodes all ofdata.byte[]decompress(byte[] data, int maxOutputSize) Decodes all ofdata, failing if the output would exceedmaxOutputSizebytes.Creates a stream of the data decoded fromin.
-
Field Details
-
DEFAULT_MAX_WINDOW_SIZE
public static final int DEFAULT_MAX_WINDOW_SIZEThe default window limit, 128 MiB: what the reference decoder accepts by default.- See Also:
-
-
Method Details
-
create
Returns a decompressor with default settings.- Returns:
- the shared, immutable default decompressor
-
builder
Creates a builder initialized with the default settings.- Returns:
- a new builder
-
inputStream
Creates a stream of the data decoded fromin.- Parameters:
in- compressed input; closing the returned stream also closes this input- Returns:
- a new decompression stream using this decompressor's settings
-
decompress
Decodes all ofdata.- Parameters:
data- compressed frames- Returns:
- the concatenated decompressed contents
- Throws:
ZstdException- if the data is invalid or exceeds the decoder's limits
-
decompress
Decodes all ofdata, failing if the output would exceedmaxOutputSizebytes.- Parameters:
data- compressed framesmaxOutputSize- 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
-