A small self-contained program that uses the Huffman Algorithm to pack and unpack files
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.settings
samples
src/com/huffmancoding/hctutorial
.classpath
.gitignore
.project
README.md
hctutorial.mf

README.md

hctutorial

This Java tool is an implementation of the Huffman Coding algorithm.

The old Unix pack command used Huffman Coding, so the term is used here although the file format of this Java code is not compatible with the old "C" code.

PROGRAM ARGUMENTS

There are no command line arguments. When run, it will display a file chooser dialog prompting for a text file to pack. A ".packed" file will be created.

PROGRAM INPUT

This program currently assumes the file contains characters and uses a Reader. It will:

  • Count the number of characters in the input.
  • Build leaf nodes for each unique character with its frequency.
  • Build a combined Huffman tree from the leaf nodes.
  • Serialize the Huffman tree into a packed file.
  • Re-read the original, computing an MD5 checksum, and appending the packed content.
  • Read the Huffman tree back in from the file just written.
  • Read the content from the remainder of the packed file and unpacking it.
  • Computes an MD5 checksum of the contents that were unpacked.
  • Displaying the before and after MD5 checksums

PROGRAM OUTPUT

It creates a ".packed" file.

While it unpacks the packed file in memory to verify that it was created correctly, it does not create an unpacked file on disk from a .packed file.

FUTURE ENHANCEMENTS

Allow the program to take command line arguments to indicate whether to pack or unpack.