/** * Compresses the input string literal using the Huffman coding. * @param out the output stream for the compressed data * @param data the string literal to be Huffman encoded * @throws IOException if an I/O error occurs. * @see com.twitter.hpack.HuffmanEncoder#encode(OutputStream, byte[], int, int) */ public void encode(OutputStream out, byte[] data) throws IOException { encode(out, data, 0, data.length); }
/** * Encode string literal according to Section 5.2. */ private void encodeStringLiteral(OutputStream out, byte[] string) throws IOException { int huffmanLength = Huffman.ENCODER.getEncodedLength(string); if ((huffmanLength < string.length && !forceHuffmanOff) || forceHuffmanOn) { encodeInteger(out, 0x80, 7, huffmanLength); Huffman.ENCODER.encode(out, string); } else { encodeInteger(out, 0x00, 7, string.length); out.write(string, 0, string.length); } }
/** * Encode string literal according to Section 5.2. */ private void encodeStringLiteral(OutputStream out, byte[] string) throws IOException { int huffmanLength = Huffman.ENCODER.getEncodedLength(string); if ((huffmanLength < string.length && !forceHuffmanOff) || forceHuffmanOn) { encodeInteger(out, 0x80, 7, huffmanLength); Huffman.ENCODER.encode(out, string); } else { encodeInteger(out, 0x00, 7, string.length); out.write(string, 0, string.length); } }
/** * Compresses the input string literal using the Huffman coding. * @param out the output stream for the compressed data * @param data the string literal to be Huffman encoded * @throws IOException if an I/O error occurs. * @see com.twitter.hpack.HuffmanEncoder#encode(OutputStream, byte[], int, int) */ public void encode(OutputStream out, byte[] data) throws IOException { encode(out, data, 0, data.length); }