1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.compression;
17
18 import org.jboss.netty.util.internal.jzlib.JZlib;
19 import org.jboss.netty.util.internal.jzlib.ZStream;
20
21
22
23
24 final class ZlibUtil {
25
26 static void fail(ZStream z, String message, int resultCode) {
27 throw exception(z, message, resultCode);
28 }
29
30 static CompressionException exception(ZStream z, String message, int resultCode) {
31 return new CompressionException(message + " (" + resultCode + ')' +
32 (z.msg != null? ": " + z.msg : ""));
33 }
34
35 static Enum<?> convertWrapperType(ZlibWrapper wrapper) {
36 Enum<?> convertedWrapperType;
37 switch (wrapper) {
38 case NONE:
39 convertedWrapperType = JZlib.W_NONE;
40 break;
41 case ZLIB:
42 convertedWrapperType = JZlib.W_ZLIB;
43 break;
44 case GZIP:
45 convertedWrapperType = JZlib.W_GZIP;
46 break;
47 case ZLIB_OR_NONE:
48 convertedWrapperType = JZlib.W_ZLIB_OR_NONE;
49 break;
50 default:
51 throw new Error();
52 }
53 return convertedWrapperType;
54 }
55
56 static int wrapperOverhead(ZlibWrapper wrapper) {
57 int overhead;
58 switch (wrapper) {
59 case NONE:
60 overhead = 0;
61 break;
62 case ZLIB:
63 case ZLIB_OR_NONE:
64 overhead = 2;
65 break;
66 case GZIP:
67 overhead = 10;
68 break;
69 default:
70 throw new Error();
71 }
72 return overhead;
73 }
74
75 private ZlibUtil() {
76 }
77 }