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.SystemPropertyUtil;
19 import io.netty.util.internal.logging.InternalLogger;
20 import io.netty.util.internal.logging.InternalLoggerFactory;
21
22
23
24
25 public final class ZlibCodecFactory {
26 private static final InternalLogger logger = InternalLoggerFactory.getInstance(ZlibCodecFactory.class);
27
28 private static final int DEFAULT_JDK_WINDOW_SIZE = 15;
29 private static final int DEFAULT_JDK_MEM_LEVEL = 8;
30
31 private static final boolean noJdkZlibDecoder;
32 private static final boolean noJdkZlibEncoder;
33
34 static {
35 noJdkZlibDecoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibDecoder", false);
36 logger.debug("-Dio.netty.noJdkZlibDecoder: {}", noJdkZlibDecoder);
37
38 noJdkZlibEncoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibEncoder", false);
39 logger.debug("-Dio.netty.noJdkZlibEncoder: {}", noJdkZlibEncoder);
40 }
41
42
43
44
45 public static boolean isSupportingWindowSizeAndMemLevel() {
46 return true;
47 }
48
49 public static ZlibEncoder newZlibEncoder(int compressionLevel) {
50 if (noJdkZlibEncoder) {
51 return new JZlibEncoder(compressionLevel);
52 } else {
53 return new JdkZlibEncoder(compressionLevel);
54 }
55 }
56
57 public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper) {
58 if (noJdkZlibEncoder) {
59 return new JZlibEncoder(wrapper);
60 } else {
61 return new JdkZlibEncoder(wrapper);
62 }
63 }
64
65 public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel) {
66 if (noJdkZlibEncoder) {
67 return new JZlibEncoder(wrapper, compressionLevel);
68 } else {
69 return new JdkZlibEncoder(wrapper, compressionLevel);
70 }
71 }
72
73 public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {
74 if (noJdkZlibEncoder ||
75 windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
76 return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel);
77 } else {
78 return new JdkZlibEncoder(wrapper, compressionLevel);
79 }
80 }
81
82 public static ZlibEncoder newZlibEncoder(byte[] dictionary) {
83 if (noJdkZlibEncoder) {
84 return new JZlibEncoder(dictionary);
85 } else {
86 return new JdkZlibEncoder(dictionary);
87 }
88 }
89
90 public static ZlibEncoder newZlibEncoder(int compressionLevel, byte[] dictionary) {
91 if (noJdkZlibEncoder) {
92 return new JZlibEncoder(compressionLevel, dictionary);
93 } else {
94 return new JdkZlibEncoder(compressionLevel, dictionary);
95 }
96 }
97
98 public static ZlibEncoder newZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) {
99 if (noJdkZlibEncoder ||
100 windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
101 return new JZlibEncoder(compressionLevel, windowBits, memLevel, dictionary);
102 } else {
103 return new JdkZlibEncoder(compressionLevel, dictionary);
104 }
105 }
106
107 public static ZlibDecoder newZlibDecoder() {
108 if (noJdkZlibDecoder) {
109 return new JZlibDecoder();
110 } else {
111 return new JdkZlibDecoder(true);
112 }
113 }
114
115 public static ZlibDecoder newZlibDecoder(ZlibWrapper wrapper) {
116 if (noJdkZlibDecoder) {
117 return new JZlibDecoder(wrapper);
118 } else {
119 return new JdkZlibDecoder(wrapper, true);
120 }
121 }
122
123 public static ZlibDecoder newZlibDecoder(byte[] dictionary) {
124 if (noJdkZlibDecoder) {
125 return new JZlibDecoder(dictionary);
126 } else {
127 return new JdkZlibDecoder(dictionary);
128 }
129 }
130
131 private ZlibCodecFactory() {
132
133 }
134 }