@@ -8,8 +8,8 @@ Task-focused recipes. Each assumes you have the library on the classpath (see th
88Reuse a context to amortise native allocation across many calls:
99
1010``` java
11- try (ZstdCompressCtx cctx = new ZstdCompressCtx (). level(19 );
12- ZstdDecompressCtx dctx = new ZstdDecompressCtx ()) {
11+ try (ZstdCompressContext cctx = new ZstdCompressContext (). level(19 );
12+ ZstdDecompressContext dctx = new ZstdDecompressContext ()) {
1313 byte [] packed = cctx. compress(message);
1414 byte [] restored = dctx. decompress(packed, message. length);
1515}
@@ -26,7 +26,7 @@ or to abort a half-written frame and start clean — without freeing and recreat
2626it. Pick what to clear with ` ZstdResetDirective ` :
2727
2828``` java
29- try (ZstdCompressCtx cctx = new ZstdCompressCtx (). level(19 )) {
29+ try (ZstdCompressContext cctx = new ZstdCompressContext (). level(19 )) {
3030 byte [] a = cctx. compress(first);
3131
3232 // Cheap: drop any unflushed frame state, keep the level and parameters.
@@ -39,7 +39,7 @@ try (ZstdCompressCtx cctx = new ZstdCompressCtx().level(19)) {
3939}
4040```
4141
42- ` ZstdDecompressCtx .reset(...)` works the same way. Reuse alone amortises
42+ ` ZstdDecompressContext .reset(...)` works the same way. Reuse alone amortises
4343allocation; reset lets a long-lived or pooled context return to a known state
4444without churning native memory.
4545
@@ -51,7 +51,7 @@ matching) set on the context. To combine the two, make the dictionary *sticky*
5151with ` loadDictionary ` — then the normal ` compress ` path honours both:
5252
5353``` java
54- try (ZstdCompressCtx cctx = new ZstdCompressCtx (). level(19 ). checksum(true )) {
54+ try (ZstdCompressContext cctx = new ZstdCompressContext (). level(19 ). checksum(true )) {
5555 cctx. loadDictionary(dict); // ZstdDictionary, or a native MemorySegment
5656 byte [] frame = cctx. compress(record); // dictionary + checksum, together
5757}
@@ -62,9 +62,9 @@ by reference — no per-call digesting, no copy. It pairs with `reset` for a
6262pooled, recycled context:
6363
6464``` java
65- try (ZstdCompressDict cdict = dict. compressDict(19 )) {
65+ try (ZstdCompressDictionary cdict = dict. compressDict(19 )) {
6666 // one cctx per pooled worker, all sharing the one digested dictionary
67- try (ZstdCompressCtx cctx = new ZstdCompressCtx ()) {
67+ try (ZstdCompressContext cctx = new ZstdCompressContext ()) {
6868 cctx. refDictionary(cdict); // borrowed; cdict must outlive cctx
6969 byte [] a = cctx. compress(first);
7070 cctx. reset(ZstdResetDirective . SESSION_ONLY ); // recycle, keep the dictionary
@@ -76,12 +76,12 @@ try (ZstdCompressDict cdict = dict.compressDict(19)) {
7676` refDictionary ` only borrows: the digested ` cdict ` is * not* tied to the context's
7777lifetime, so it must be closed separately (hence its own try-with-resources). That
7878is the price of sharing one digest across many contexts. If you have just ** one**
79- context, don't build a ` ZstdCompressDict ` at all — ` loadDictionary ` above digests
79+ context, don't build a ` ZstdCompressDictionary ` at all — ` loadDictionary ` above digests
8080into the context and frees it for you, and a stray, never-closed
81- ` ZstdCompressDict ` is a native-memory leak.
81+ ` ZstdCompressDictionary ` is a native-memory leak.
8282
8383A loaded or referenced dictionary stays until replaced, cleared with ` null ` , or
84- dropped by a parameter ` reset ` . ` ZstdDecompressCtx ` mirrors all of this.
84+ dropped by a parameter ` reset ` . ` ZstdDecompressContext ` mirrors all of this.
8585
8686## Compress many small payloads with a dictionary
8787
@@ -92,8 +92,8 @@ representative samples:
9292``` java
9393ZstdDictionary dict = ZstdDictionary . train(sampleRecords, 16 * 1024 );
9494
95- try (ZstdCompressCtx cctx = new ZstdCompressCtx ();
96- ZstdDecompressCtx dctx = new ZstdDecompressCtx ()) {
95+ try (ZstdCompressContext cctx = new ZstdCompressContext ();
96+ ZstdDecompressContext dctx = new ZstdDecompressContext ()) {
9797 byte [] packed = cctx. compress(record, dict);
9898 byte [] restored = dctx. decompress(packed, record. length, dict);
9999}
@@ -105,10 +105,10 @@ ZstdDictionary reloaded = ZstdDictionary.of(persisted);
105105On a hot path, digest the dictionary once to skip per-call setup:
106106
107107``` java
108- try (ZstdCompressDict cdict = dict. compressDict(19 );
109- ZstdDecompressDict ddict = dict. decompressDict();
110- ZstdCompressCtx cctx = new ZstdCompressCtx ();
111- ZstdDecompressCtx dctx = new ZstdDecompressCtx ()) {
108+ try (ZstdCompressDictionary cdict = dict. compressDict(19 );
109+ ZstdDecompressDictionary ddict = dict. decompressDict();
110+ ZstdCompressContext cctx = new ZstdCompressContext ();
111+ ZstdDecompressContext dctx = new ZstdDecompressContext ()) {
112112 byte [] packed = cctx. compress(record, cdict);
113113 byte [] restored = dctx. decompress(packed, record. length, ddict);
114114}
@@ -122,7 +122,7 @@ hands zstd the segment address directly: no copy in, no copy out, no GC churn.
122122
123123``` java
124124try (Arena arena = Arena . ofConfined();
125- ZstdDecompressCtx dctx = new ZstdDecompressCtx ()) {
125+ ZstdDecompressContext dctx = new ZstdDecompressContext ()) {
126126 MemorySegment frame = reader. mmapSlice(); // already native
127127 long n = Zstd . decompressedSize(frame); // read header, no copy
128128 MemorySegment out = arena. allocate(n); // becomes the backing buffer
@@ -138,10 +138,10 @@ The segment-API map:
138138
139139| Operation | byte[ ] (convenience) | MemorySegment (boundary zero-copy) |
140140| ------------------------| -------------------------------------------------| ----------------------------------------------------|
141- | compress | ` ZstdCompressCtx .compress(byte[])` | ` ZstdCompressCtx .compress(dst, src)` |
142- | compress + dict | ` ZstdCompressCtx .compress(byte[], ZstdCompressDict )` | ` ZstdCompressCtx .compress(dst, src, ZstdCompressDict )` |
143- | decompress | ` ZstdDecompressCtx .decompress(byte[], int)` | ` ZstdDecompressCtx .decompress(dst, src)` |
144- | decompress + dict | ` ZstdDecompressCtx .decompress(byte[], int, ZstdDecompressDict )` | ` ZstdDecompressCtx .decompress(dst, src, ZstdDecompressDict )` |
141+ | compress | ` ZstdCompressContext .compress(byte[])` | ` ZstdCompressContext .compress(dst, src)` |
142+ | compress + dict | ` ZstdCompressContext .compress(byte[], ZstdCompressDictionary )` | ` ZstdCompressContext .compress(dst, src, ZstdCompressDictionary )` |
143+ | decompress | ` ZstdDecompressContext .decompress(byte[], int)` | ` ZstdDecompressContext .decompress(dst, src)` |
144+ | decompress + dict | ` ZstdDecompressContext .decompress(byte[], int, ZstdDecompressDictionary )` | ` ZstdDecompressContext .decompress(dst, src, ZstdDecompressDictionary )` |
145145| size output (no copy) | frame header via ` Zstd.decompress(byte[]) ` | ` Zstd.decompressedSize(MemorySegment) ` |
146146
147147Size ` dst ` with ` Zstd.compressBound(srcSize) ` for compression, or
@@ -177,7 +177,7 @@ direct buffer or a `byte[]` first.
177177
178178``` java
179179try (Arena arena = Arena . ofConfined();
180- ZstdCompressCtx cctx = new ZstdCompressCtx ()) {
180+ ZstdCompressContext cctx = new ZstdCompressContext ()) {
181181 ByteBuffer src = channel. map(READ_ONLY , 0 , size, arena); // direct, off-heap
182182 MemorySegment in = MemorySegment . ofBuffer(src); // covers [position, limit)
183183 MemorySegment out = cctx. compress(arena, in); // arena-owned frame
0 commit comments