src/java.net.http/share/classes/jdk/internal/net/http/hpack/QuickHuffman.java
author chegar
Wed, 20 Jun 2018 18:23:56 +0100
branchhttp-client-branch
changeset 56795 03ece2518428
parent 56639 bd0dba2a0d51
parent 50681 4254bed3c09d
permissions -rw-r--r--
http-client-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     1
/*
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     4
 *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    10
 *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    15
 * accompanied this code).
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    16
 *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    20
 *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    23
 * questions.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    24
 */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    25
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    26
package jdk.internal.net.http.hpack;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    27
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    28
import jdk.internal.net.http.hpack.HPACK.BufferUpdateConsumer;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    29
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    30
import java.io.IOException;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    31
import java.nio.ByteBuffer;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    32
import java.util.List;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    33
import java.util.Objects;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    34
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    35
import static jdk.internal.net.http.hpack.HPACK.bytesForBits;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    36
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    37
public final class QuickHuffman {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    38
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    39
    /*
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    40
     * Mapping of characters to their code information. Code information
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    41
     * consists of a code value and a code length. Both components are packed in
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    42
     * a single long as follows:
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    43
     *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    44
     *     MSB                             LSB
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    45
     *     +----------------+----------------+
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    46
     *     |~code           |         length~|
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    47
     *     +----------------+----------------+
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    48
     *     |<----- 32 ----->|<----- 32 ----->|
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    49
     *     |<------------- 64 -------------->|
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    50
     *
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    51
     * The leftmost 32 bits hold the code value. This value is aligned left (or
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    52
     * MSB). The rightmost 32 bits hold the code length. This length is aligned
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    53
     * right (or LSB). Such structure is possible thanks to codes being up to 30
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    54
     * bits long and their lengths being up to 5 bits long (length = 5..30).
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    55
     * This allows both components to fit into long and, thus, better locality.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    56
     *
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    57
     * Input strings never contain EOS. Thus there's no need to provide EOS
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    58
     * mapping. Hence, the length of the array is 256, not 257.
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    59
     */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    60
    private static final long[] codes = new long[256];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    61
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    62
    private static long codeValueOf(char c) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    63
        return codes[c] & 0xffffffff00000000L;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    64
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    65
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    66
    private static long codeLengthOf(char c) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    67
        return codes[c] & 0x00000000ffffffffL;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    68
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    69
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    70
    private static final int EOS_LENGTH = 30;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    71
    private static final int EOS_LSB = 0x3fffffff;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    72
    // EOS_LSB is casted to long before the shift, to allow long shift (6 bits)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    73
    // instead of int shift (5 bits):
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    74
    private static final long EOS_MSB = ((long) EOS_LSB) << (64 - EOS_LENGTH);
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    75
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    76
    /*
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    77
     * Huffman trie.
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    78
     *
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    79
     * The root node leads to 257 descendant leaf nodes, of which 256 nodes
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    80
     * correspond to characters and 1 node correspond to EOS.
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    81
     */
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    82
    private static final Node root = buildTrie();
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    83
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
    84
    private static Node buildTrie() {
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    85
        TemporaryNode tmpRoot = new TemporaryNode();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    86
        addChar(tmpRoot,   0, 0x1ff8,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    87
        addChar(tmpRoot,   1, 0x7fffd8,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    88
        addChar(tmpRoot,   2, 0xfffffe2,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    89
        addChar(tmpRoot,   3, 0xfffffe3,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    90
        addChar(tmpRoot,   4, 0xfffffe4,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    91
        addChar(tmpRoot,   5, 0xfffffe5,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    92
        addChar(tmpRoot,   6, 0xfffffe6,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    93
        addChar(tmpRoot,   7, 0xfffffe7,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    94
        addChar(tmpRoot,   8, 0xfffffe8,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    95
        addChar(tmpRoot,   9, 0xffffea,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    96
        addChar(tmpRoot,  10, 0x3ffffffc, 30);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    97
        addChar(tmpRoot,  11, 0xfffffe9,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    98
        addChar(tmpRoot,  12, 0xfffffea,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
    99
        addChar(tmpRoot,  13, 0x3ffffffd, 30);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   100
        addChar(tmpRoot,  14, 0xfffffeb,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   101
        addChar(tmpRoot,  15, 0xfffffec,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   102
        addChar(tmpRoot,  16, 0xfffffed,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   103
        addChar(tmpRoot,  17, 0xfffffee,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   104
        addChar(tmpRoot,  18, 0xfffffef,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   105
        addChar(tmpRoot,  19, 0xffffff0,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   106
        addChar(tmpRoot,  20, 0xffffff1,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   107
        addChar(tmpRoot,  21, 0xffffff2,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   108
        addChar(tmpRoot,  22, 0x3ffffffe, 30);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   109
        addChar(tmpRoot,  23, 0xffffff3,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   110
        addChar(tmpRoot,  24, 0xffffff4,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   111
        addChar(tmpRoot,  25, 0xffffff5,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   112
        addChar(tmpRoot,  26, 0xffffff6,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   113
        addChar(tmpRoot,  27, 0xffffff7,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   114
        addChar(tmpRoot,  28, 0xffffff8,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   115
        addChar(tmpRoot,  29, 0xffffff9,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   116
        addChar(tmpRoot,  30, 0xffffffa,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   117
        addChar(tmpRoot,  31, 0xffffffb,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   118
        addChar(tmpRoot,  32, 0x14,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   119
        addChar(tmpRoot,  33, 0x3f8,      10);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   120
        addChar(tmpRoot,  34, 0x3f9,      10);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   121
        addChar(tmpRoot,  35, 0xffa,      12);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   122
        addChar(tmpRoot,  36, 0x1ff9,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   123
        addChar(tmpRoot,  37, 0x15,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   124
        addChar(tmpRoot,  38, 0xf8,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   125
        addChar(tmpRoot,  39, 0x7fa,      11);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   126
        addChar(tmpRoot,  40, 0x3fa,      10);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   127
        addChar(tmpRoot,  41, 0x3fb,      10);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   128
        addChar(tmpRoot,  42, 0xf9,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   129
        addChar(tmpRoot,  43, 0x7fb,      11);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   130
        addChar(tmpRoot,  44, 0xfa,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   131
        addChar(tmpRoot,  45, 0x16,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   132
        addChar(tmpRoot,  46, 0x17,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   133
        addChar(tmpRoot,  47, 0x18,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   134
        addChar(tmpRoot,  48, 0x0,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   135
        addChar(tmpRoot,  49, 0x1,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   136
        addChar(tmpRoot,  50, 0x2,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   137
        addChar(tmpRoot,  51, 0x19,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   138
        addChar(tmpRoot,  52, 0x1a,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   139
        addChar(tmpRoot,  53, 0x1b,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   140
        addChar(tmpRoot,  54, 0x1c,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   141
        addChar(tmpRoot,  55, 0x1d,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   142
        addChar(tmpRoot,  56, 0x1e,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   143
        addChar(tmpRoot,  57, 0x1f,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   144
        addChar(tmpRoot,  58, 0x5c,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   145
        addChar(tmpRoot,  59, 0xfb,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   146
        addChar(tmpRoot,  60, 0x7ffc,     15);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   147
        addChar(tmpRoot,  61, 0x20,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   148
        addChar(tmpRoot,  62, 0xffb,      12);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   149
        addChar(tmpRoot,  63, 0x3fc,      10);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   150
        addChar(tmpRoot,  64, 0x1ffa,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   151
        addChar(tmpRoot,  65, 0x21,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   152
        addChar(tmpRoot,  66, 0x5d,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   153
        addChar(tmpRoot,  67, 0x5e,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   154
        addChar(tmpRoot,  68, 0x5f,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   155
        addChar(tmpRoot,  69, 0x60,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   156
        addChar(tmpRoot,  70, 0x61,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   157
        addChar(tmpRoot,  71, 0x62,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   158
        addChar(tmpRoot,  72, 0x63,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   159
        addChar(tmpRoot,  73, 0x64,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   160
        addChar(tmpRoot,  74, 0x65,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   161
        addChar(tmpRoot,  75, 0x66,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   162
        addChar(tmpRoot,  76, 0x67,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   163
        addChar(tmpRoot,  77, 0x68,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   164
        addChar(tmpRoot,  78, 0x69,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   165
        addChar(tmpRoot,  79, 0x6a,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   166
        addChar(tmpRoot,  80, 0x6b,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   167
        addChar(tmpRoot,  81, 0x6c,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   168
        addChar(tmpRoot,  82, 0x6d,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   169
        addChar(tmpRoot,  83, 0x6e,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   170
        addChar(tmpRoot,  84, 0x6f,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   171
        addChar(tmpRoot,  85, 0x70,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   172
        addChar(tmpRoot,  86, 0x71,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   173
        addChar(tmpRoot,  87, 0x72,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   174
        addChar(tmpRoot,  88, 0xfc,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   175
        addChar(tmpRoot,  89, 0x73,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   176
        addChar(tmpRoot,  90, 0xfd,        8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   177
        addChar(tmpRoot,  91, 0x1ffb,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   178
        addChar(tmpRoot,  92, 0x7fff0,    19);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   179
        addChar(tmpRoot,  93, 0x1ffc,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   180
        addChar(tmpRoot,  94, 0x3ffc,     14);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   181
        addChar(tmpRoot,  95, 0x22,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   182
        addChar(tmpRoot,  96, 0x7ffd,     15);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   183
        addChar(tmpRoot,  97, 0x3,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   184
        addChar(tmpRoot,  98, 0x23,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   185
        addChar(tmpRoot,  99, 0x4,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   186
        addChar(tmpRoot, 100, 0x24,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   187
        addChar(tmpRoot, 101, 0x5,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   188
        addChar(tmpRoot, 102, 0x25,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   189
        addChar(tmpRoot, 103, 0x26,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   190
        addChar(tmpRoot, 104, 0x27,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   191
        addChar(tmpRoot, 105, 0x6,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   192
        addChar(tmpRoot, 106, 0x74,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   193
        addChar(tmpRoot, 107, 0x75,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   194
        addChar(tmpRoot, 108, 0x28,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   195
        addChar(tmpRoot, 109, 0x29,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   196
        addChar(tmpRoot, 110, 0x2a,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   197
        addChar(tmpRoot, 111, 0x7,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   198
        addChar(tmpRoot, 112, 0x2b,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   199
        addChar(tmpRoot, 113, 0x76,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   200
        addChar(tmpRoot, 114, 0x2c,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   201
        addChar(tmpRoot, 115, 0x8,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   202
        addChar(tmpRoot, 116, 0x9,         5);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   203
        addChar(tmpRoot, 117, 0x2d,        6);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   204
        addChar(tmpRoot, 118, 0x77,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   205
        addChar(tmpRoot, 119, 0x78,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   206
        addChar(tmpRoot, 120, 0x79,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   207
        addChar(tmpRoot, 121, 0x7a,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   208
        addChar(tmpRoot, 122, 0x7b,        7);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   209
        addChar(tmpRoot, 123, 0x7ffe,     15);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   210
        addChar(tmpRoot, 124, 0x7fc,      11);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   211
        addChar(tmpRoot, 125, 0x3ffd,     14);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   212
        addChar(tmpRoot, 126, 0x1ffd,     13);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   213
        addChar(tmpRoot, 127, 0xffffffc,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   214
        addChar(tmpRoot, 128, 0xfffe6,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   215
        addChar(tmpRoot, 129, 0x3fffd2,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   216
        addChar(tmpRoot, 130, 0xfffe7,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   217
        addChar(tmpRoot, 131, 0xfffe8,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   218
        addChar(tmpRoot, 132, 0x3fffd3,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   219
        addChar(tmpRoot, 133, 0x3fffd4,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   220
        addChar(tmpRoot, 134, 0x3fffd5,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   221
        addChar(tmpRoot, 135, 0x7fffd9,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   222
        addChar(tmpRoot, 136, 0x3fffd6,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   223
        addChar(tmpRoot, 137, 0x7fffda,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   224
        addChar(tmpRoot, 138, 0x7fffdb,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   225
        addChar(tmpRoot, 139, 0x7fffdc,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   226
        addChar(tmpRoot, 140, 0x7fffdd,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   227
        addChar(tmpRoot, 141, 0x7fffde,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   228
        addChar(tmpRoot, 142, 0xffffeb,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   229
        addChar(tmpRoot, 143, 0x7fffdf,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   230
        addChar(tmpRoot, 144, 0xffffec,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   231
        addChar(tmpRoot, 145, 0xffffed,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   232
        addChar(tmpRoot, 146, 0x3fffd7,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   233
        addChar(tmpRoot, 147, 0x7fffe0,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   234
        addChar(tmpRoot, 148, 0xffffee,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   235
        addChar(tmpRoot, 149, 0x7fffe1,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   236
        addChar(tmpRoot, 150, 0x7fffe2,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   237
        addChar(tmpRoot, 151, 0x7fffe3,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   238
        addChar(tmpRoot, 152, 0x7fffe4,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   239
        addChar(tmpRoot, 153, 0x1fffdc,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   240
        addChar(tmpRoot, 154, 0x3fffd8,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   241
        addChar(tmpRoot, 155, 0x7fffe5,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   242
        addChar(tmpRoot, 156, 0x3fffd9,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   243
        addChar(tmpRoot, 157, 0x7fffe6,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   244
        addChar(tmpRoot, 158, 0x7fffe7,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   245
        addChar(tmpRoot, 159, 0xffffef,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   246
        addChar(tmpRoot, 160, 0x3fffda,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   247
        addChar(tmpRoot, 161, 0x1fffdd,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   248
        addChar(tmpRoot, 162, 0xfffe9,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   249
        addChar(tmpRoot, 163, 0x3fffdb,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   250
        addChar(tmpRoot, 164, 0x3fffdc,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   251
        addChar(tmpRoot, 165, 0x7fffe8,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   252
        addChar(tmpRoot, 166, 0x7fffe9,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   253
        addChar(tmpRoot, 167, 0x1fffde,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   254
        addChar(tmpRoot, 168, 0x7fffea,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   255
        addChar(tmpRoot, 169, 0x3fffdd,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   256
        addChar(tmpRoot, 170, 0x3fffde,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   257
        addChar(tmpRoot, 171, 0xfffff0,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   258
        addChar(tmpRoot, 172, 0x1fffdf,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   259
        addChar(tmpRoot, 173, 0x3fffdf,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   260
        addChar(tmpRoot, 174, 0x7fffeb,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   261
        addChar(tmpRoot, 175, 0x7fffec,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   262
        addChar(tmpRoot, 176, 0x1fffe0,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   263
        addChar(tmpRoot, 177, 0x1fffe1,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   264
        addChar(tmpRoot, 178, 0x3fffe0,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   265
        addChar(tmpRoot, 179, 0x1fffe2,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   266
        addChar(tmpRoot, 180, 0x7fffed,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   267
        addChar(tmpRoot, 181, 0x3fffe1,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   268
        addChar(tmpRoot, 182, 0x7fffee,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   269
        addChar(tmpRoot, 183, 0x7fffef,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   270
        addChar(tmpRoot, 184, 0xfffea,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   271
        addChar(tmpRoot, 185, 0x3fffe2,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   272
        addChar(tmpRoot, 186, 0x3fffe3,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   273
        addChar(tmpRoot, 187, 0x3fffe4,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   274
        addChar(tmpRoot, 188, 0x7ffff0,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   275
        addChar(tmpRoot, 189, 0x3fffe5,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   276
        addChar(tmpRoot, 190, 0x3fffe6,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   277
        addChar(tmpRoot, 191, 0x7ffff1,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   278
        addChar(tmpRoot, 192, 0x3ffffe0,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   279
        addChar(tmpRoot, 193, 0x3ffffe1,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   280
        addChar(tmpRoot, 194, 0xfffeb,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   281
        addChar(tmpRoot, 195, 0x7fff1,    19);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   282
        addChar(tmpRoot, 196, 0x3fffe7,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   283
        addChar(tmpRoot, 197, 0x7ffff2,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   284
        addChar(tmpRoot, 198, 0x3fffe8,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   285
        addChar(tmpRoot, 199, 0x1ffffec,  25);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   286
        addChar(tmpRoot, 200, 0x3ffffe2,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   287
        addChar(tmpRoot, 201, 0x3ffffe3,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   288
        addChar(tmpRoot, 202, 0x3ffffe4,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   289
        addChar(tmpRoot, 203, 0x7ffffde,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   290
        addChar(tmpRoot, 204, 0x7ffffdf,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   291
        addChar(tmpRoot, 205, 0x3ffffe5,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   292
        addChar(tmpRoot, 206, 0xfffff1,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   293
        addChar(tmpRoot, 207, 0x1ffffed,  25);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   294
        addChar(tmpRoot, 208, 0x7fff2,    19);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   295
        addChar(tmpRoot, 209, 0x1fffe3,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   296
        addChar(tmpRoot, 210, 0x3ffffe6,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   297
        addChar(tmpRoot, 211, 0x7ffffe0,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   298
        addChar(tmpRoot, 212, 0x7ffffe1,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   299
        addChar(tmpRoot, 213, 0x3ffffe7,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   300
        addChar(tmpRoot, 214, 0x7ffffe2,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   301
        addChar(tmpRoot, 215, 0xfffff2,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   302
        addChar(tmpRoot, 216, 0x1fffe4,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   303
        addChar(tmpRoot, 217, 0x1fffe5,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   304
        addChar(tmpRoot, 218, 0x3ffffe8,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   305
        addChar(tmpRoot, 219, 0x3ffffe9,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   306
        addChar(tmpRoot, 220, 0xffffffd,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   307
        addChar(tmpRoot, 221, 0x7ffffe3,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   308
        addChar(tmpRoot, 222, 0x7ffffe4,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   309
        addChar(tmpRoot, 223, 0x7ffffe5,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   310
        addChar(tmpRoot, 224, 0xfffec,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   311
        addChar(tmpRoot, 225, 0xfffff3,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   312
        addChar(tmpRoot, 226, 0xfffed,    20);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   313
        addChar(tmpRoot, 227, 0x1fffe6,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   314
        addChar(tmpRoot, 228, 0x3fffe9,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   315
        addChar(tmpRoot, 229, 0x1fffe7,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   316
        addChar(tmpRoot, 230, 0x1fffe8,   21);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   317
        addChar(tmpRoot, 231, 0x7ffff3,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   318
        addChar(tmpRoot, 232, 0x3fffea,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   319
        addChar(tmpRoot, 233, 0x3fffeb,   22);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   320
        addChar(tmpRoot, 234, 0x1ffffee,  25);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   321
        addChar(tmpRoot, 235, 0x1ffffef,  25);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   322
        addChar(tmpRoot, 236, 0xfffff4,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   323
        addChar(tmpRoot, 237, 0xfffff5,   24);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   324
        addChar(tmpRoot, 238, 0x3ffffea,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   325
        addChar(tmpRoot, 239, 0x7ffff4,   23);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   326
        addChar(tmpRoot, 240, 0x3ffffeb,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   327
        addChar(tmpRoot, 241, 0x7ffffe6,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   328
        addChar(tmpRoot, 242, 0x3ffffec,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   329
        addChar(tmpRoot, 243, 0x3ffffed,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   330
        addChar(tmpRoot, 244, 0x7ffffe7,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   331
        addChar(tmpRoot, 245, 0x7ffffe8,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   332
        addChar(tmpRoot, 246, 0x7ffffe9,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   333
        addChar(tmpRoot, 247, 0x7ffffea,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   334
        addChar(tmpRoot, 248, 0x7ffffeb,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   335
        addChar(tmpRoot, 249, 0xffffffe,  28);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   336
        addChar(tmpRoot, 250, 0x7ffffec,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   337
        addChar(tmpRoot, 251, 0x7ffffed,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   338
        addChar(tmpRoot, 252, 0x7ffffee,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   339
        addChar(tmpRoot, 253, 0x7ffffef,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   340
        addChar(tmpRoot, 254, 0x7fffff0,  27);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   341
        addChar(tmpRoot, 255, 0x3ffffee,  26);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   342
        addEOS (tmpRoot, 256, EOS_LSB, EOS_LENGTH);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   343
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   344
        // The difference in performance can always be checked by not using
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   345
        // the immutable trie:
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   346
        //     return tmpRoot;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   347
        return ImmutableNode.copyOf(tmpRoot);
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   348
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   349
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   350
    private QuickHuffman() { }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   351
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   352
    private static void addChar(Node root, int symbol, int code, int bitLength)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   353
    {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   354
        addLeaf(root, (char) symbol, code, bitLength, false);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   355
        long value = ((long) code) << (64 - bitLength); // re-align MSB <- LSB
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   356
        codes[symbol] = value | bitLength;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   357
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   358
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   359
    private static void addEOS(Node root, int symbol, int code, int bitLength)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   360
    {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   361
        addLeaf(root, (char) symbol, code, bitLength, true);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   362
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   363
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   364
    private static void addLeaf(Node root,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   365
                                char symbol,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   366
                                int code,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   367
                                int bitLength,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   368
                                boolean isEOS)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   369
    {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   370
        assert 0 < bitLength && bitLength <= 32 : bitLength;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   371
        Node curr = root;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   372
        int nBytes = bytesForBits(bitLength);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   373
        // The number of bits the code needs to be shifted to the left in order
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   374
        // to align with the byte #nBytes boundary:
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   375
        int align = (nBytes << 3) - bitLength;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   376
        code <<= align;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   377
        // descend the trie until the last element
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   378
        int l = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   379
        for (int i = 0, probe = 0xff << ((nBytes - 1) << 3);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   380
             i < nBytes - 1;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   381
             i++, probe >>>= 8)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   382
        {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   383
            curr.setEOSPath(curr.isEOSPath() | isEOS);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   384
            int idx = (code & probe) >>> ((nBytes - 1 - i) << 3);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   385
            curr = curr.getOrCreateChild(idx);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   386
            curr.setLength(8);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   387
            l += 8;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   388
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   389
        // Assign the same char to all byte variants. For example, if the code
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   390
        // and its length are 00011b and 5 respectively (letter 'a') then, in
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   391
        // order to be able to match any byte starting with 00011b prefix,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   392
        // the following nodes need to be created:
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   393
        //
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   394
        //     00011000b, 00011001b, 00011010b, 00011011b, 00011100b, 00011101b,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   395
        //     00011110b and 00011111b
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   396
        int idx = code & 0xff;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   397
        curr.setEOSPath(curr.isEOSPath() | isEOS);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   398
        for (int i = 0; i < (1 << align); i++) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   399
            Node child = curr.getOrCreateChild(idx | i);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   400
            child.setSymbol(symbol);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   401
            child.setEOSPath(child.isEOSPath() | isEOS);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   402
            child.setLength(bitLength - l);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   403
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   404
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   405
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   406
    /*
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   407
     * A node in the Huffman trie.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   408
     */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   409
    interface Node {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   410
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   411
        boolean isEOSPath();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   412
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   413
        void setEOSPath(boolean value);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   414
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   415
        boolean isLeaf();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   416
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   417
        Node getChild(int index);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   418
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   419
        Node getOrCreateChild(int index);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   420
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   421
        Node[] getChildren();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   422
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   423
        char getSymbol();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   424
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   425
        void setSymbol(char symbol);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   426
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   427
        int getLength();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   428
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   429
        void setLength(int value);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   430
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   431
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   432
    /*
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   433
     * Mutable nodes used for initial construction of the Huffman trie.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   434
     * (These nodes are perfectly ok to be used after that.)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   435
     */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   436
    static final class TemporaryNode implements Node {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   437
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   438
        private char symbol;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   439
        private boolean eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   440
        private TemporaryNode[] children;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   441
        private int length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   442
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   443
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   444
        public TemporaryNode getOrCreateChild(int index) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   445
            ensureChildrenExist();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   446
            if (children[index] == null) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   447
                children[index] = new TemporaryNode();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   448
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   449
            return children[index];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   450
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   451
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   452
        private void ensureChildrenExist() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   453
            if (children == null) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   454
                children = new TemporaryNode[256];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   455
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   456
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   457
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   458
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   459
        public boolean isLeaf() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   460
            return children == null;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   461
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   462
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   463
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   464
        public boolean isEOSPath() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   465
            return eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   466
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   467
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   468
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   469
        public void setEOSPath(boolean value) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   470
            eosPath = value;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   471
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   472
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   473
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   474
        public TemporaryNode getChild(int index) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   475
            ensureChildrenExist();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   476
            return children[index];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   477
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   478
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   479
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   480
        public Node[] getChildren() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   481
            if (children == null) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   482
                return new Node[0];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   483
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   484
            return children;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   485
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   486
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   487
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   488
        public char getSymbol() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   489
            return symbol;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   490
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   491
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   492
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   493
        public int getLength() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   494
            return length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   495
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   496
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   497
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   498
        public void setSymbol(char value) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   499
            this.symbol = value;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   500
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   501
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   502
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   503
        public void setLength(int value) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   504
            this.length = value;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   505
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   506
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   507
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   508
    /*
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   509
     * Immutable node used to construct traversal-only Huffman trie.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   510
     *
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   511
     * Once the trie has been built, the support of modifications is no longer
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   512
     * required. An immutable trie should be used. Not only it will help to
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   513
     * catch possible bugs, but hopefully speedup the traversal operations.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   514
     */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   515
    static final class ImmutableNode implements Node {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   516
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   517
        private final char symbol;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   518
        private final boolean eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   519
        private final int length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   520
        private final List<ImmutableNode> children;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   521
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   522
        public static ImmutableNode copyOf(Node node) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   523
            if (node.isLeaf()) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   524
                return new ImmutableNode(node.getSymbol(), node.isEOSPath(),
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   525
                                         node.getLength());
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   526
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   527
            Node[] children = node.getChildren();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   528
            ImmutableNode[] immutableChildren = new ImmutableNode[children.length];
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   529
            for (int i = 0; i < children.length; i++) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   530
                immutableChildren[i] = copyOf(children[i]);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   531
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   532
            return new ImmutableNode(node.isEOSPath(), node.getLength(),
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   533
                                     immutableChildren);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   534
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   535
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   536
        /* Creates a leaf node */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   537
        private ImmutableNode(char symbol,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   538
                              boolean eosPath,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   539
                              int length) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   540
            this.symbol = symbol;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   541
            this.eosPath = eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   542
            this.length = length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   543
            this.children = List.of();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   544
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   545
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   546
        /* Creates a node with children */
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   547
        private ImmutableNode(boolean eosPath,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   548
                              int length,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   549
                              ImmutableNode[] children)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   550
        {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   551
            this.symbol = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   552
            this.eosPath = eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   553
            this.length = length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   554
            if (children.length == 0) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   555
                throw new IllegalArgumentException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   556
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   557
            // A list produced by List.of should not be slower than array for
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   558
            // accessing elements by index, and hopefully use additional
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   559
            // optimizations (e.g. jdk.internal.vm.annotation.Stable)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   560
            this.children = List.of(children);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   561
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   562
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   563
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   564
        public boolean isLeaf() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   565
            return children.isEmpty();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   566
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   567
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   568
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   569
        public boolean isEOSPath() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   570
            return eosPath;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   571
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   572
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   573
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   574
        public void setEOSPath(boolean value) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   575
            throw new UnsupportedOperationException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   576
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   577
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   578
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   579
        public ImmutableNode getChild(int index) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   580
            return children.get(index);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   581
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   582
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   583
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   584
        public ImmutableNode getOrCreateChild(int index) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   585
            throw new UnsupportedOperationException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   586
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   587
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   588
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   589
        public ImmutableNode[] getChildren() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   590
            // This method is not expected to be called on an immutable node.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   591
            // If it is called, it requires some investigation.
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   592
            throw new UnsupportedOperationException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   593
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   594
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   595
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   596
        public char getSymbol() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   597
            return symbol;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   598
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   599
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   600
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   601
        public void setSymbol(char symbol) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   602
            throw new UnsupportedOperationException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   603
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   604
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   605
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   606
        public int getLength() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   607
            return length;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   608
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   609
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   610
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   611
        public void setLength(int value) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   612
            throw new UnsupportedOperationException();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   613
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   614
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   615
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   616
    static final class Reader implements Huffman.Reader {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   617
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   618
        private final BufferUpdateConsumer UPDATER =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   619
                (buf, bufLen) -> {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   620
                    buffer = buf;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   621
                    bufferLen = bufLen;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   622
                };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   623
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   624
        private Node curr = root;  // current position in the trie
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   625
        private long buffer;       // bits left from the previous match (aligned to the left, or MSB)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   626
        private int bufferLen;     // number of bits in the buffer
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   627
        private int len;           // length (in bits) of path to curr
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   628
        private boolean done;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   629
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   630
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   631
        public void read(ByteBuffer source,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   632
                         Appendable destination,
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   633
                         boolean isLast) throws IOException
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   634
        {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   635
            while (!done) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   636
                int remaining = source.remaining();
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   637
                int nBytes = HPACK.read(source, buffer, bufferLen, UPDATER);
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   638
                // write as much as possible
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   639
                while (true) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   640
                    if (bufferLen < 8) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   641
                        if (nBytes < remaining) { // read again
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   642
                            break;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   643
                        } else if (!isLast) { // exit the method to accept more input
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   644
                            return;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   645
                        } else if (bufferLen > 0) { // no more data is expected, pad
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   646
                                                    // (this padding may be done more than once)
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   647
                            buffer |= ((0xff00000000000000L >>> bufferLen)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   648
                                    & 0xff00000000000000L);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   649
                            // do not update bufferLen, since all those ones are
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   650
                            // synthetic and are appended merely for the sake of
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   651
                            // lookup
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   652
                        } else {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   653
                            done = true;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   654
                            break;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   655
                        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   656
                    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   657
                    int idx = (int) (buffer >>> 56);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   658
                    Node node = curr.getChild(idx);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   659
                    if (node == null) { // TODO: TEST
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   660
                        throw new IOException("Unexpected byte");
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   661
                    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   662
                    if (node.isLeaf()) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   663
                        if (node.getLength() > bufferLen) { // matched more than we actually could (because of padding)
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   664
                            throw new IOException(
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   665
                                    "Not a EOS prefix padding or unexpected end of data");
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   666
                        }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   667
                        if (node.isEOSPath()) {
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   668
                            throw new IOException("Encountered EOS");
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   669
                        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   670
                        destination.append(node.getSymbol());
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   671
                        curr = root;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   672
                        len = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   673
                    } else {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   674
                        curr = node;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   675
                        // because of the padding, we can't match more bits than
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   676
                        // there are currently in the buffer
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   677
                        len += Math.min(bufferLen, node.getLength());
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   678
                    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   679
                    buffer <<= node.getLength();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   680
                    bufferLen -= node.getLength();
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   681
                }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   682
                if (done && (curr.isEOSPath() && len > 7)) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   683
                    throw new IOException(
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   684
                            "Padding is too long (len=" + len + ") "
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   685
                                    + "or unexpected end of data");
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   686
                }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   687
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   688
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   689
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   690
        @Override
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   691
        public void reset() {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   692
            curr = root;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   693
            len = 0;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   694
            buffer = 0;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   695
            bufferLen = 0;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   696
            done = false;
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   697
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   698
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   699
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   700
    static final class Writer implements Huffman.Writer {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   701
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   702
        private final BufferUpdateConsumer UPDATER =
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   703
                (buf, bufLen) -> {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   704
                    buffer = buf;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   705
                    bufferLen = bufLen;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   706
                };
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   707
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   708
        private CharSequence source;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   709
        private boolean padded;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   710
        private int pos;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   711
        private int end;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   712
        private long buffer;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   713
        private int bufferLen;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   714
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   715
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   716
        public QuickHuffman.Writer from(CharSequence input, int start, int end) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   717
            Objects.checkFromToIndex(start, end, input.length());
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   718
            this.pos = start;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   719
            this.end = end;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   720
            this.source = input;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   721
            return this;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   722
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   723
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   724
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   725
        public boolean write(ByteBuffer destination) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   726
            while (true) {
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   727
                while (true) { // stuff codes into long
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   728
                    if (pos >= end) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   729
                        break;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   730
                    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   731
                    char c = source.charAt(pos);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   732
                    if (c > 255) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   733
                        throw new IllegalArgumentException("char=" + ((int) c));
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   734
                    }
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   735
                    long len = codeLengthOf(c);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   736
                    if (bufferLen + len <= 64) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   737
                        buffer |= (codeValueOf(c) >>> bufferLen); // append
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   738
                        bufferLen += len;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   739
                        pos++;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   740
                    } else {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   741
                        break;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   742
                    }
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   743
                }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   744
                if (bufferLen == 0) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   745
                    return true;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   746
                }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   747
                if (pos >= end && !padded) { // no more input chars are expected, pad
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   748
                    padded = true;
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   749
                    // A long shift to 64 will result in the same long, not
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   750
                    // necessarily 0L. In which case padding will be performed
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   751
                    // incorrectly. If bufferLen is equal to 64, the shift (and
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   752
                    // padding) in not performed.
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   753
                    // (see https://docs.oracle.com/javase/specs/jls/se10/html/jls-15.html#jls-15.19)
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   754
                    if (bufferLen != 64) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   755
                        buffer |= (EOS_MSB >>> bufferLen);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   756
                        bufferLen = bytesForBits(bufferLen) << 3;
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   757
                    }
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   758
                }
50681
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   759
                int nBytes = HPACK.write(buffer, bufferLen, UPDATER, destination);
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   760
                if (nBytes == 0) {
4254bed3c09d 8204679: HTTP Client refresh
chegar
parents: 49944
diff changeset
   761
                    return false;
49944
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   762
                }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   763
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   764
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   765
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   766
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   767
        public QuickHuffman.Writer reset() {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   768
            source = null;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   769
            buffer = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   770
            bufferLen = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   771
            end = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   772
            pos = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   773
            padded = false;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   774
            return this;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   775
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   776
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   777
        @Override
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   778
        public int lengthOf(CharSequence value, int start, int end) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   779
            int len = 0;
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   780
            for (int i = start; i < end; i++) {
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   781
                char c = value.charAt(i);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   782
                len += codeLengthOf(c);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   783
            }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   784
            return bytesForBits(len);
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   785
        }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   786
    }
4690a2871b44 8202423: Small HTTP Client refresh
chegar
parents:
diff changeset
   787
}