Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.compress
Class Huff

java.lang.Object
  extended by ch.rgw.compress.Huff

public class Huff
extends java.lang.Object

Simple implementation of the Huffman compression algorithm. Consists solely of static functions.
To compress data:

  1. Load, create or use a frequency table for the data to compress: (Tree.constructTable(), Tree.loadTable(), Tree.useTable())
  2. Create a Huffman tree and obtain its root Node: new Tree().build(table);
  3. compress the data: encode()
  4. expand the data: decode()
  5. This implementation uses an extension to the straightforward algorithm to deal with the situation of a character being written, which was not in the table, and with end-of-file conditions. In such cases, an escape character (0x07) will be written and specially interpreted

    Author:
    Gerry

    Field Summary
    static int eof
               
    static byte escape
               
     
    Constructor Summary
    Huff()
               
     
    Method Summary
    static byte[] decode(HuffmanTree tree, byte[] source)
              Huffman decode the source array
    static java.lang.String decodeString(HuffmanTree tree, byte[] in)
              Decode a previously with encodeString compressed String
    static byte[] encode(HuffmanTree tree, byte[] source)
              Huffman encode the source array
    static byte[] encodeString(HuffmanTree tree, java.lang.String i)
              Huffman encode a String
    static void main(java.lang.String[] argv)
              The main function can be used to accomplish a few tasks regarding persistent storage of Huffman tables.: java -classpath . ch.rgw.tools.Compress.Huff list: shows all stored tables in the system Preferences java -classpath . ch.rgw.tools.Compress.Huff create : computes a frequency table of the and stores ist as in the preferences.
    static java.lang.String Version()
               
    static void writeEOF(ch.rgw.compress.HuffmanTree.Node act, BitOutputStream out)
               
     
    Methods inherited from class java.lang.Object
    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    escape

    public static final byte escape
    See Also:
    Constant Field Values

    eof

    public static final int eof
    See Also:
    Constant Field Values
    Constructor Detail

    Huff

    public Huff()
    Method Detail

    Version

    public static java.lang.String Version()

    encode

    public static byte[] encode(HuffmanTree tree,
                                byte[] source)
    Huffman encode the source array

    Parameters:
    tree - a Hufmann tree as created by new Tree() or null
    source - the source to compress. If tree is null, the Tree will be computed from the source first and its frequency table is included in the output.
    Returns:
    The huffman compressed source

    decode

    public static byte[] decode(HuffmanTree tree,
                                byte[] source)
    Huffman decode the source array

    Parameters:
    tree - a Huffman tree as created by new Tree() or null
    source - A huffman compressed array as returned by encode(). If tree is null, the frequency count is expected to be included to the source.
    Returns:
    the decoded data or null on error.

    encodeString

    public static byte[] encodeString(HuffmanTree tree,
                                      java.lang.String i)
    Huffman encode a String


    decodeString

    public static java.lang.String decodeString(HuffmanTree tree,
                                                byte[] in)
    Decode a previously with encodeString compressed String


    writeEOF

    public static void writeEOF(ch.rgw.compress.HuffmanTree.Node act,
                                BitOutputStream out)
                         throws java.io.IOException
    Throws:
    java.io.IOException

    main

    public static void main(java.lang.String[] argv)
    The main function can be used to accomplish a few tasks regarding persistent storage of Huffman tables.:
    • java -classpath . ch.rgw.tools.Compress.Huff list: shows all stored tables in the system Preferences
    • java -classpath . ch.rgw.tools.Compress.Huff create : computes a frequency table of the and stores ist as in the preferences.
    • java -classpath . ch.rgw.tools.Compress.Huff export : exports the table from the preferences into two files:
      • .bin: A binary representation (sequence of bytes)
      • .asc: A textual representation (comma separated list)


    Elexis API documentation
    Version 2.1.6 as of December 11 2011

    Copyright 2005-2011 by Gerry Weirich, Elexis