@@ -46,6 +46,11 @@ public class HuffmanDecompressor implements Decompressor {
4646 */
4747 private ByteWriter byteWriter ;
4848
49+ /**
50+ * Root node of the Huffman tree
51+ */
52+ private HuffmanNode huffmanTreeRoot ;
53+
4954 /**
5055 * Constructor that takes a compressed file path and generates the Huffman code mapping
5156 * @param compressedFilePath The path to the compressed file to be decompressed
@@ -86,8 +91,8 @@ private Map<String, Integer> generateHuffmanCodesFromZipFile(String compressedFi
8691 } catch (IOException e ) {
8792 throw new RuntimeException ("Failed to read frequency table from compressed file: " + compressedFilePath , e );
8893 }
89- HuffmanNode root = HuffmanUtils .buildHuffmanTree (frequency );
90- String [] huffmanCodes = HuffmanUtils .generateHuffmanCodes (root );
94+ huffmanTreeRoot = HuffmanUtils .buildHuffmanTree (frequency );
95+ String [] huffmanCodes = HuffmanUtils .generateHuffmanCodes (huffmanTreeRoot );
9196 for (i = 0 ; i < Constants .BYTE_VALUES_COUNT ; i ++) {
9297 if (huffmanCodes [i ] != null && huffmanCodes [i ].length () > 0 ) {
9398 huffmancodeToByteMap .put (huffmanCodes [i ], i );
@@ -136,6 +141,7 @@ private int getExtraBits(int uniqueCharCount) throws IOException {
136141 */
137142 private void processCompressedBytes (BitReader bitReader ) throws IOException {
138143 String [] byteToBinaryStrings = HuffmanUtils .createBinaryStringsForBytes ();
144+ HuffmanNode currentNode = huffmanTreeRoot ;
139145 while (true ) {
140146 Byte currentByte = this .byteReader .readNextByte ();
141147 if (currentByte == null ) break ;
0 commit comments