1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.compression;
18
19 import io.netty.util.internal.PlatformDependent;
20 import io.netty.util.internal.logging.InternalLogger;
21 import io.netty.util.internal.logging.InternalLoggerFactory;
22
23 public final class Zstd {
24
25 private static final InternalLogger logger = InternalLoggerFactory.getInstance(Zstd.class);
26 private static final Throwable cause;
27
28 static {
29 Throwable t = null;
30
31 try {
32 Class.forName("com.github.luben.zstd.Zstd", false,
33 PlatformDependent.getClassLoader(Zstd.class));
34 } catch (ClassNotFoundException e) {
35 t = e;
36 logger.debug(
37 "zstd-jni not in the classpath; Zstd support will be unavailable.");
38 } catch (Throwable e) {
39 t = e;
40 logger.debug("Failed to load zstd-jni; Zstd support will be unavailable.", t);
41 }
42
43 cause = t;
44 }
45
46
47
48
49
50
51 public static boolean isAvailable() {
52 return cause == null;
53 }
54
55
56
57
58
59
60 public static void ensureAvailability() throws Throwable {
61 if (cause != null) {
62 throw cause;
63 }
64 }
65
66
67
68
69 public static Throwable cause() {
70 return cause;
71 }
72
73 private Zstd() {
74 }
75 }