Question: Have multiple Java files for huffman code: Huff.java HuffC.java FileIO.java FileIOC.java Bit.java BitC.java etc.... How do I utilize the code written in FileIO/IOC that compresses

Have multiple Java files for huffman code:

Huff.java

HuffC.java

FileIO.java

FileIOC.java

Bit.java

BitC.java

etc....

How do I utilize the code written in FileIO/IOC that compresses the file into huff code in the huff model to solve:

Create a new (empty) symbol table.

Open the input text file. For each unique character (or symbol) in the input file, create an entry in the symbol table for that symbol. Use the symbol table entry to count the frequency of the character in the input file. Close the input file when done.

Create a new priority queue for Huffman trees. Recall that the compareTo function for Huffman trees compares trees by their weights. For each key (i.e., symbol) K in the symbol table, look up it's frequency f and create a Huffman tree leaf node with weight f. Insert the leaf node into the priority queue.

While the priority queue has more than one element, remove two trees t1 and t2 from the priority queue. Construct a new tree t with t1 and t2 as left and right children (resp.) and with weight = t1.weight() + t2.weight(). Insert the new tree t into the priority queue.

The priority queue now contains exactly one element: the Huffman coding tree for the input text. Remove the tree from the priority queue. Recursively walk the coding tree recording the binary bit path P at each step. When the recursive walk arrives at a leaf with symbol A, update A's binary bit pattern entry in the symbol table to record the binary path that led from the root to leaf A.

The symbol table now has the information required to write the variable length codes to the binary output file.

Open the binary output file.

Write the signature bits to identify the file as a zip file.

Write out the 32-bit length of the symbol table.

Next write out the symbol frequency information. For each key in the symbol table, write the key (i.e., the character) using one byte and write its integer frequency using 4 bytes.

Reopen the input file.

For each occurrence of a character in the input file, look up it's binary bit pattern in the symbol table and write it to the output file.

Close the output file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!