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