public class Huffman
extends java.lang.Object
To be most effective, Huffman encoding uses a variable length code, where no code is a prefix of another, which makes decompression easier by allowing the extraction of the file bit-by-bit. The shortest codes are assigned to the most common characters, with infrequent characters receiving longer codes.
Objects to be compressed must be Serializable.
HuffmanEncoded| Constructor and Description |
|---|
Huffman() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Object |
decode(HuffmanEncoded enc)
Decodes a compressed object using the Huffman algorithm.
|
static HuffmanEncoded |
encode(java.lang.Object obj)
Encodes an object using Huffman compression.
|
public static HuffmanEncoded encode(java.lang.Object obj) throws java.io.IOException
obj - serializable object to be compressedHuffmanEncoded object containing the compressed
object and its encoding tablejava.io.IOException - when an I/O exception is thrown by an underlying java.io.* classHuffmanEncodedpublic static java.lang.Object decode(HuffmanEncoded enc) throws java.io.IOException, java.lang.ClassNotFoundException
enc - object to be decompressedObjectjava.io.IOException - when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException - when an explicit cast failsHuffmanEncoded