/** * Creates a new Huffman decoder with the specified Huffman coding. * @param codes the Huffman codes indexed by symbol * @param lengths the length of each Huffman code */ HuffmanDecoder(int[] codes, byte[] lengths) { if (codes.length != 257 || codes.length != lengths.length) { throw new IllegalArgumentException("invalid Huffman coding"); } root = buildTree(codes, lengths); }
private byte[] readStringLiteral(InputStream in, int length) throws IOException { byte[] buf = new byte[length]; if (in.read(buf) != length) { throw DECOMPRESSION_EXCEPTION; } if (huffmanEncoded) { return Huffman.DECODER.decode(buf); } else { return buf; } }
private static Node buildTree(int[] codes, byte[] lengths) { Node root = new Node(); for (int i = 0; i < codes.length; i++) { insert(root, i, codes[i], lengths[i]); } return root; }
private static Node buildTree(int[] codes, byte[] lengths) { Node root = new Node(); for (int i = 0; i < codes.length; i++) { insert(root, i, codes[i], lengths[i]); } return root; }
/** * Creates a new Huffman decoder with the specified Huffman coding. * @param codes the Huffman codes indexed by symbol * @param lengths the length of each Huffman code */ HuffmanDecoder(int[] codes, byte[] lengths) { if (codes.length != 257 || codes.length != lengths.length) { throw new IllegalArgumentException("invalid Huffman coding"); } root = buildTree(codes, lengths); }
private byte[] readStringLiteral(InputStream in, int length) throws IOException { byte[] buf = new byte[length]; if (in.read(buf) != length) { throw DECOMPRESSION_EXCEPTION; } if (huffmanEncoded) { return Huffman.DECODER.decode(buf); } else { return buf; } }