JAVA huffman tree compression example.

This code example demonstrates a compression technique using a Huffman tree.
It reads a text from a textfile. Then it composes the Huffman tree for the given text in memory.
Contents of the tree is printed to the command line. Afterwards the bitset is decompressed to the original text.
The program also prints the compression rate.

Example print of the program:

Read line from file: pannenkoek
The buffer length: 10
Number of characters in the map: 6
Contents of the map: {o=1, k=2, a=1, p=1, n=3, e=2}
HuffMan tree composed!
e is transformed to bitset: 00
k is transformed to bitset: 01
a is transformed to bitset: 100
p is transformed to bitset: 1010
o is transformed to bitset: 1011
n is transformed to bitset: 11
The following values that are present in the Map: {o=1011, k=01, a=100, p=1010, n=11, e=00}
The compressed BitSet consists of : 26 bits
The original text consists of : 80 bits
Character found: p
Character found: a
Character found: n
Character found: n
Character found: e
Character found: n
Character found: k
Character found: o
Character found: e
Character found: k
The bitstring recomposed to text gives as result: pannenkoek
			

Downloads

Source code huffman.zip
Discussion: Click here to post/read comments on this assignment