Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdDecompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
/// state allocation. Not thread-safe: confine an instance to one thread or pool it.
public final class ZstdDecompressCtx extends NativeObject {

private static final String COMPRESSED = "compressed";

/// Creates a new decompression context.
public ZstdDecompressCtx() {
super(create());
Expand Down Expand Up @@ -53,7 +55,7 @@ public ZstdDecompressCtx windowLogMax(int windowLogMax) {
/// @param maxSize upper bound on the decompressed length
/// @return the original bytes
public byte[] decompress(byte[] compressed, int maxSize) {
Objects.requireNonNull(compressed, "compressed");
Objects.requireNonNull(compressed, COMPRESSED);
try (Arena arena = Arena.ofConfined()) {
MemorySegment in = Zstd.copyIn(arena, compressed);
MemorySegment out = arena.allocate(Math.max(maxSize, 1));
Expand All @@ -74,7 +76,7 @@ public byte[] decompress(byte[] compressed, int maxSize) {
/// @param dict the dictionary the frame was compressed against
/// @return the original bytes
public byte[] decompress(byte[] compressed, int maxSize, ZstdDictionary dict) {
Objects.requireNonNull(compressed, "compressed");
Objects.requireNonNull(compressed, COMPRESSED);
Objects.requireNonNull(dict, "dict");
try (Arena arena = Arena.ofConfined()) {
MemorySegment in = Zstd.copyIn(arena, compressed);
Expand All @@ -94,7 +96,7 @@ public byte[] decompress(byte[] compressed, int maxSize, ZstdDictionary dict) {
/// @param dict the pre-digested decompression dictionary
/// @return the original bytes
public byte[] decompress(byte[] compressed, int maxSize, ZstdDecompressDict dict) {
Objects.requireNonNull(compressed, "compressed");
Objects.requireNonNull(compressed, COMPRESSED);
Objects.requireNonNull(dict, "dict");
try (Arena arena = Arena.ofConfined()) {
MemorySegment in = Zstd.copyIn(arena, compressed);
Expand Down
7 changes: 4 additions & 3 deletions zstd/src/main/java/io/github/dfa1/zstd/ZstdDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class ZstdDictionary {

private static final String FIELD_NB_THREADS = "nbThreads";
private static final String FIELD_COMPRESSION_LEVEL = "compressionLevel";
private static final String SAMPLES = "samples";

// ZDICT_cover_params_t fields: unsigned k, d, steps, nbThreads; double
// splitPoint; unsigned shrinkDict, shrinkDictMaxRegression; then a nested
Expand Down Expand Up @@ -94,7 +95,7 @@ public static ZstdDictionary of(byte[] raw) {
/// @return the trained dictionary
/// @throws ZstdException if training fails (commonly: not enough sample data)
public static ZstdDictionary train(List<byte[]> samples, int maxDictBytes) {
Objects.requireNonNull(samples, "samples");
Objects.requireNonNull(samples, SAMPLES);
if (samples.isEmpty()) {
throw new ZstdException("cannot train a dictionary from zero samples");
}
Expand Down Expand Up @@ -178,7 +179,7 @@ public static ZstdDictionary trainFastCover(List<byte[]> samples, int maxDictByt

private static ZstdDictionary optimize(List<byte[]> samples, int maxDictBytes,
int compressionLevel, boolean fast) {
Objects.requireNonNull(samples, "samples");
Objects.requireNonNull(samples, SAMPLES);
if (samples.isEmpty()) {
throw new ZstdException("cannot train a dictionary from zero samples");
}
Expand Down Expand Up @@ -233,7 +234,7 @@ private static ZstdDictionary optimize(List<byte[]> samples, int maxDictBytes,
public static ZstdDictionary finalizeFrom(byte[] content, List<byte[]> samples,
int maxDictBytes, int compressionLevel) {
Objects.requireNonNull(content, "content");
Objects.requireNonNull(samples, "samples");
Objects.requireNonNull(samples, SAMPLES);
if (samples.isEmpty()) {
throw new ZstdException("cannot finalise a dictionary from zero samples");
}
Expand Down
Loading