1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.compression;
17
18 import io.netty5.util.internal.ObjectUtil;
19
20 import static io.netty5.handler.codec.compression.ZstdConstants.DEFAULT_BLOCK_SIZE;
21 import static io.netty5.handler.codec.compression.ZstdConstants.DEFAULT_COMPRESSION_LEVEL;
22 import static io.netty5.handler.codec.compression.ZstdConstants.MAX_BLOCK_SIZE;
23 import static io.netty5.handler.codec.compression.ZstdConstants.MAX_COMPRESSION_LEVEL;
24
25
26
27
28
29 public class ZstdOptions implements CompressionOptions {
30
31 private final int blockSize;
32 private final int compressionLevel;
33 private final int maxEncodeSize;
34
35
36
37
38
39
40 static final ZstdOptions DEFAULT = new ZstdOptions(DEFAULT_COMPRESSION_LEVEL, DEFAULT_BLOCK_SIZE, MAX_BLOCK_SIZE);
41
42
43
44
45
46
47
48
49
50
51
52 ZstdOptions(int compressionLevel, int blockSize, int maxEncodeSize) {
53 if (!Zstd.isAvailable()) {
54 throw new IllegalStateException("zstd-jni is not available", Zstd.cause());
55 }
56
57 this.compressionLevel = ObjectUtil.checkInRange(compressionLevel, 0, MAX_COMPRESSION_LEVEL, "compressionLevel");
58 this.blockSize = ObjectUtil.checkPositive(blockSize, "blockSize");
59 this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
60 }
61
62 public int compressionLevel() {
63 return compressionLevel;
64 }
65
66 public int blockSize() {
67 return blockSize;
68 }
69
70 public int maxEncodeSize() {
71 return maxEncodeSize;
72 }
73 }