View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http2.hpack;
29  
30  import org.apache.hc.core5.annotation.Internal;
31  
32  /**
33   * This Huffman codec implementation has been derived from Twitter HPack project
34   * (https://github.com/twitter/hpack)
35   */
36  @Internal
37  public final class Huffman {
38  
39      private Huffman() {
40          // Do not allow utility class to be instantiated.
41      }
42  
43      static final int[] CODES = {
44              0x1ff8,
45              0x7fffd8,
46              0xfffffe2,
47              0xfffffe3,
48              0xfffffe4,
49              0xfffffe5,
50              0xfffffe6,
51              0xfffffe7,
52              0xfffffe8,
53              0xffffea,
54              0x3ffffffc,
55              0xfffffe9,
56              0xfffffea,
57              0x3ffffffd,
58              0xfffffeb,
59              0xfffffec,
60              0xfffffed,
61              0xfffffee,
62              0xfffffef,
63              0xffffff0,
64              0xffffff1,
65              0xffffff2,
66              0x3ffffffe,
67              0xffffff3,
68              0xffffff4,
69              0xffffff5,
70              0xffffff6,
71              0xffffff7,
72              0xffffff8,
73              0xffffff9,
74              0xffffffa,
75              0xffffffb,
76              0x14,
77              0x3f8,
78              0x3f9,
79              0xffa,
80              0x1ff9,
81              0x15,
82              0xf8,
83              0x7fa,
84              0x3fa,
85              0x3fb,
86              0xf9,
87              0x7fb,
88              0xfa,
89              0x16,
90              0x17,
91              0x18,
92              0x0,
93              0x1,
94              0x2,
95              0x19,
96              0x1a,
97              0x1b,
98              0x1c,
99              0x1d,
100             0x1e,
101             0x1f,
102             0x5c,
103             0xfb,
104             0x7ffc,
105             0x20,
106             0xffb,
107             0x3fc,
108             0x1ffa,
109             0x21,
110             0x5d,
111             0x5e,
112             0x5f,
113             0x60,
114             0x61,
115             0x62,
116             0x63,
117             0x64,
118             0x65,
119             0x66,
120             0x67,
121             0x68,
122             0x69,
123             0x6a,
124             0x6b,
125             0x6c,
126             0x6d,
127             0x6e,
128             0x6f,
129             0x70,
130             0x71,
131             0x72,
132             0xfc,
133             0x73,
134             0xfd,
135             0x1ffb,
136             0x7fff0,
137             0x1ffc,
138             0x3ffc,
139             0x22,
140             0x7ffd,
141             0x3,
142             0x23,
143             0x4,
144             0x24,
145             0x5,
146             0x25,
147             0x26,
148             0x27,
149             0x6,
150             0x74,
151             0x75,
152             0x28,
153             0x29,
154             0x2a,
155             0x7,
156             0x2b,
157             0x76,
158             0x2c,
159             0x8,
160             0x9,
161             0x2d,
162             0x77,
163             0x78,
164             0x79,
165             0x7a,
166             0x7b,
167             0x7ffe,
168             0x7fc,
169             0x3ffd,
170             0x1ffd,
171             0xffffffc,
172             0xfffe6,
173             0x3fffd2,
174             0xfffe7,
175             0xfffe8,
176             0x3fffd3,
177             0x3fffd4,
178             0x3fffd5,
179             0x7fffd9,
180             0x3fffd6,
181             0x7fffda,
182             0x7fffdb,
183             0x7fffdc,
184             0x7fffdd,
185             0x7fffde,
186             0xffffeb,
187             0x7fffdf,
188             0xffffec,
189             0xffffed,
190             0x3fffd7,
191             0x7fffe0,
192             0xffffee,
193             0x7fffe1,
194             0x7fffe2,
195             0x7fffe3,
196             0x7fffe4,
197             0x1fffdc,
198             0x3fffd8,
199             0x7fffe5,
200             0x3fffd9,
201             0x7fffe6,
202             0x7fffe7,
203             0xffffef,
204             0x3fffda,
205             0x1fffdd,
206             0xfffe9,
207             0x3fffdb,
208             0x3fffdc,
209             0x7fffe8,
210             0x7fffe9,
211             0x1fffde,
212             0x7fffea,
213             0x3fffdd,
214             0x3fffde,
215             0xfffff0,
216             0x1fffdf,
217             0x3fffdf,
218             0x7fffeb,
219             0x7fffec,
220             0x1fffe0,
221             0x1fffe1,
222             0x3fffe0,
223             0x1fffe2,
224             0x7fffed,
225             0x3fffe1,
226             0x7fffee,
227             0x7fffef,
228             0xfffea,
229             0x3fffe2,
230             0x3fffe3,
231             0x3fffe4,
232             0x7ffff0,
233             0x3fffe5,
234             0x3fffe6,
235             0x7ffff1,
236             0x3ffffe0,
237             0x3ffffe1,
238             0xfffeb,
239             0x7fff1,
240             0x3fffe7,
241             0x7ffff2,
242             0x3fffe8,
243             0x1ffffec,
244             0x3ffffe2,
245             0x3ffffe3,
246             0x3ffffe4,
247             0x7ffffde,
248             0x7ffffdf,
249             0x3ffffe5,
250             0xfffff1,
251             0x1ffffed,
252             0x7fff2,
253             0x1fffe3,
254             0x3ffffe6,
255             0x7ffffe0,
256             0x7ffffe1,
257             0x3ffffe7,
258             0x7ffffe2,
259             0xfffff2,
260             0x1fffe4,
261             0x1fffe5,
262             0x3ffffe8,
263             0x3ffffe9,
264             0xffffffd,
265             0x7ffffe3,
266             0x7ffffe4,
267             0x7ffffe5,
268             0xfffec,
269             0xfffff3,
270             0xfffed,
271             0x1fffe6,
272             0x3fffe9,
273             0x1fffe7,
274             0x1fffe8,
275             0x7ffff3,
276             0x3fffea,
277             0x3fffeb,
278             0x1ffffee,
279             0x1ffffef,
280             0xfffff4,
281             0xfffff5,
282             0x3ffffea,
283             0x7ffff4,
284             0x3ffffeb,
285             0x7ffffe6,
286             0x3ffffec,
287             0x3ffffed,
288             0x7ffffe7,
289             0x7ffffe8,
290             0x7ffffe9,
291             0x7ffffea,
292             0x7ffffeb,
293             0xffffffe,
294             0x7ffffec,
295             0x7ffffed,
296             0x7ffffee,
297             0x7ffffef,
298             0x7fffff0,
299             0x3ffffee,
300             0x3fffffff
301     };
302 
303     static final byte[] LENGTHS = {
304             13, 23, 28, 28, 28, 28, 28, 28, 28, 24, 30, 28, 28, 30, 28, 28,
305             28, 28, 28, 28, 28, 28, 30, 28, 28, 28, 28, 28, 28, 28, 28, 28,
306             6, 10, 10, 12, 13, 6, 8, 11, 10, 10, 8, 11, 8, 6, 6, 6,
307             5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 8, 15, 6, 12, 10,
308             13, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
309             7, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 13, 19, 13, 14, 6,
310             15, 5, 6, 5, 6, 5, 6, 6, 6, 5, 7, 7, 6, 6, 6, 5,
311             6, 7, 6, 5, 5, 6, 7, 7, 7, 7, 7, 15, 11, 14, 13, 28,
312             20, 22, 20, 20, 22, 22, 22, 23, 22, 23, 23, 23, 23, 23, 24, 23,
313             24, 24, 22, 23, 24, 23, 23, 23, 23, 21, 22, 23, 22, 23, 23, 24,
314             22, 21, 20, 22, 22, 23, 23, 21, 23, 22, 22, 24, 21, 22, 23, 23,
315             21, 21, 22, 21, 23, 22, 23, 23, 20, 22, 22, 22, 23, 22, 22, 23,
316             26, 26, 20, 19, 22, 23, 22, 25, 26, 26, 26, 27, 27, 26, 24, 25,
317             19, 21, 26, 27, 27, 26, 27, 24, 21, 21, 26, 26, 28, 27, 27, 27,
318             20, 24, 20, 21, 22, 21, 21, 23, 22, 22, 25, 25, 24, 24, 26, 23,
319             26, 27, 26, 26, 27, 27, 27, 27, 27, 28, 27, 27, 27, 27, 27, 26,
320             30
321     };
322 
323     static final int EOS = 256;
324 
325     static final HuffmanEncoder/HuffmanEncoder.html#HuffmanEncoder">HuffmanEncoder ENCODER = new HuffmanEncoder(CODES, LENGTHS);
326 
327     static final HuffmanDecoder/HuffmanDecoder.html#HuffmanDecoder">HuffmanDecoder DECODER = new HuffmanDecoder(CODES, LENGTHS);
328 
329 }