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 com.jcraft.jzlib.Deflater;
19 import com.jcraft.jzlib.Inflater;
20 import com.jcraft.jzlib.JZlib;
21
22
23
24
25 final class ZlibUtil {
26
27 static void fail(Inflater z, String message, int resultCode) {
28 throw inflaterException(z, message, resultCode);
29 }
30
31 static void fail(Deflater z, String message, int resultCode) {
32 throw deflaterException(z, message, resultCode);
33 }
34
35 static DecompressionException inflaterException(Inflater z, String message, int resultCode) {
36 return new DecompressionException(message + " (" + resultCode + ')' + (z.msg != null? ": " + z.msg : ""));
37 }
38
39 static CompressionException deflaterException(Deflater z, String message, int resultCode) {
40 return new CompressionException(message + " (" + resultCode + ')' + (z.msg != null? ": " + z.msg : ""));
41 }
42
43 static JZlib.WrapperType convertWrapperType(ZlibWrapper wrapper) {
44 JZlib.WrapperType convertedWrapperType;
45 switch (wrapper) {
46 case NONE:
47 convertedWrapperType = JZlib.W_NONE;
48 break;
49 case ZLIB:
50 convertedWrapperType = JZlib.W_ZLIB;
51 break;
52 case GZIP:
53 convertedWrapperType = JZlib.W_GZIP;
54 break;
55 case ZLIB_OR_NONE:
56 convertedWrapperType = JZlib.W_ANY;
57 break;
58 default:
59 throw new Error();
60 }
61 return convertedWrapperType;
62 }
63
64 static int wrapperOverhead(ZlibWrapper wrapper) {
65 int overhead;
66 switch (wrapper) {
67 case NONE:
68 overhead = 0;
69 break;
70 case ZLIB:
71 case ZLIB_OR_NONE:
72 overhead = 2;
73 break;
74 case GZIP:
75 overhead = 10;
76 break;
77 default:
78 throw new Error();
79 }
80 return overhead;
81 }
82
83 private ZlibUtil() {
84 }
85 }