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 }
39
40
41 if (t == null) {
42 try {
43 com.github.luben.zstd.util.Native.load();
44 } catch (Throwable e) {
45 t = e;
46 logger.debug("Failed to load zstd-jni; Zstd support will be unavailable.", t);
47 }
48 }
49 cause = t;
50 }
51
52
53
54
55
56
57 public static boolean isAvailable() {
58 return cause == null;
59 }
60
61
62
63
64
65
66 public static void ensureAvailability() throws Throwable {
67 if (cause != null) {
68 throw cause;
69 }
70 }
71
72
73
74
75 public static Throwable cause() {
76 return cause;
77 }
78
79 private Zstd() {
80 }
81 }