Add Zstd.isAvailable() check in ZstdOptions (#11597)
Motivation: At present, the verification methods of `ZstdOptions` and `BrotliOptions` are not consistent, and the processing methods of `ZstdOptions` and `BrotliOptions` in `HttpContentCompressor` are also inconsistent. The http2 module does not add zstd-jni dependency, so `ClassNotFoundException` may be thrown Modification: Added `Zstd.isAvailable()` check in `ZstdOptions` to be consistent, and added zstd-jni dependency in http2 module Result: The verification methods of `ZstdOptions` and `BrotliOptions` are consistent, and `ClassNotFoundException` will not be thrown Signed-off-by: xingrufei <xingrufei@sogou-inc.com>
This commit is contained in:
parent
009497f5f9
commit
aa69d5b5cf
@ -186,8 +186,7 @@ public class HttpContentCompressor extends HttpContentEncoder {
|
||||
} else if (compressionOption instanceof DeflateOptions) {
|
||||
deflateOptions = (DeflateOptions) compressionOption;
|
||||
} else if (compressionOption instanceof ZstdOptions) {
|
||||
// zstd might not be available
|
||||
zstdOptions = Zstd.isAvailable() ? (ZstdOptions) compressionOption : null;
|
||||
zstdOptions = (ZstdOptions) compressionOption;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported " + CompressionOptions.class.getSimpleName() +
|
||||
": " + compressionOption);
|
||||
|
@ -95,6 +95,11 @@
|
||||
<artifactId>brotli4j</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.luben</groupId>
|
||||
<artifactId>zstd-jni</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
@ -34,11 +34,11 @@ public final class BrotliOptions implements CompressionOptions {
|
||||
);
|
||||
|
||||
BrotliOptions(Encoder.Parameters parameters) {
|
||||
this.parameters = ObjectUtil.checkNotNull(parameters, "Parameters");
|
||||
|
||||
if (!Brotli.isAvailable()) {
|
||||
throw new IllegalStateException("Brotli is not available", Brotli.cause());
|
||||
}
|
||||
|
||||
this.parameters = ObjectUtil.checkNotNull(parameters, "Parameters");
|
||||
}
|
||||
|
||||
public Encoder.Parameters parameters() {
|
||||
|
@ -50,6 +50,10 @@ public class ZstdOptions implements CompressionOptions {
|
||||
* specifies the level of the compression
|
||||
*/
|
||||
ZstdOptions(int compressionLevel, int blockSize, int maxEncodeSize) {
|
||||
if (!Zstd.isAvailable()) {
|
||||
throw new IllegalStateException("zstd-jni is not available", Zstd.cause());
|
||||
}
|
||||
|
||||
this.compressionLevel = ObjectUtil.checkInRange(compressionLevel, 0, MAX_COMPRESSION_LEVEL, "compressionLevel");
|
||||
this.blockSize = ObjectUtil.checkPositive(blockSize, "blockSize");
|
||||
this.maxEncodeSize = ObjectUtil.checkPositive(maxEncodeSize, "maxEncodeSize");
|
||||
|
Loading…
Reference in New Issue
Block a user