void encode(String data, ByteBuffer out) {
        long current = 0;
        int n = 0;
        for (byte bb : data.getBytes()) {
            int b = bb & 0xFF;
            int code = CODES[b];
            int nbits = CODE_LENGTHS[b];

            current <<= nbits;
            current |= code;
            n += nbits;

            while (n >= 8) {
                n -= 8;
                out.put((byte) (current >> n));
            }
        }

        if (n > 0) {
            current <<= (8 - n);
            current |= (0xFF >>> n);
            out.put((byte) current);
        }
    }
This class was originally composed from the following classes in <a
href="https://github.com/twitter/hpack">Twitter Hpack</a>.
<p>
<ul>
<li>{@code com.twitter.hpack.HuffmanEncoder}</li>
<li>{@code com.twitter.hpack.HuffmanDecoder}</li>
<li>{@code com.twitter.hpack.HpackUtil}</li>
</ul>
netbare-core/src/main/java/com/github/megatronking/netbare/http2/Huffman.java