View Javadoc
1   /*
2    * Copyright 2012 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty5.handler.codec.compression;
17  
18  import io.netty5.channel.ChannelHandler;
19  
20  /**
21   * Creates a new ZLIB encoder / decoder.
22   */
23  public final class ZlibCodecFactory {
24      private static final boolean supportsWindowSizeAndMemLevel = true;
25  
26      /**
27       * Returns {@code true} if specify a custom window size and mem level is supported.
28       */
29      public static boolean isSupportingWindowSizeAndMemLevel() {
30          return supportsWindowSizeAndMemLevel;
31      }
32  
33      public static ChannelHandler newZlibEncoder(int compressionLevel) {
34          return new CompressionHandler(ZlibCompressor.newFactory(compressionLevel));
35      }
36  
37      public static ChannelHandler newZlibEncoder(ZlibWrapper wrapper) {
38          return new CompressionHandler(ZlibCompressor.newFactory(wrapper));
39      }
40  
41      public static ChannelHandler newZlibEncoder(ZlibWrapper wrapper, int compressionLevel) {
42          return new CompressionHandler(ZlibCompressor.newFactory(wrapper, compressionLevel));
43      }
44  
45      public static ChannelHandler newZlibEncoder(ZlibWrapper wrapper, int compressionLevel,
46                                                  int windowBits, int memLevel) {
47          return new CompressionHandler(ZlibCompressor.newFactory(wrapper, compressionLevel));
48      }
49  
50      public static ChannelHandler newZlibEncoder(byte[] dictionary) {
51          return new CompressionHandler(ZlibCompressor.newFactory(dictionary));
52      }
53  
54      public static ChannelHandler newZlibEncoder(int compressionLevel, byte[] dictionary) {
55          return new CompressionHandler(ZlibCompressor.newFactory(compressionLevel, dictionary));
56      }
57  
58      public static ChannelHandler newZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary) {
59          return new CompressionHandler(ZlibCompressor.newFactory(compressionLevel, dictionary));
60      }
61  
62      public static ChannelHandler newZlibDecoder() {
63          return new DecompressionHandler(ZlibDecompressor.newFactory(true));
64      }
65  
66      public static ChannelHandler newZlibDecoder(ZlibWrapper wrapper) {
67          return new DecompressionHandler(ZlibDecompressor.newFactory(wrapper, true));
68      }
69  
70      public static ChannelHandler newZlibDecoder(byte[] dictionary) {
71          return new DecompressionHandler(ZlibDecompressor.newFactory(dictionary));
72      }
73  
74      private ZlibCodecFactory() {
75          // Unused
76      }
77  }