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