Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.compress
Class HuffmanTree

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

public class HuffmanTree
extends java.lang.Object


Field Summary
 int[] freq
           
static byte[] TextDeutsch
          Standard table for German text
 
Constructor Summary
HuffmanTree()
           
HuffmanTree(byte[] source)
          create a Huffman Tree from a given source.
HuffmanTree(int[] frequencyTable)
          create a Huffman Tree from a frequency table (which must be an Integer Array of exactly 255 elements)
 
Method Summary
 ch.rgw.compress.HuffmanTree.Node build(int[] table)
          Build a tree from a frequency table.
static boolean checkCompacter()
           
static int[] constructTable(byte[] source)
          constructs a frequency table from an array of bytes
 java.io.InputStream constructTable(java.io.InputStream source, boolean copy)
          Construct a frequency table from an InputStream.
static int[] constructTable(java.io.RandomAccessFile file)
          constructs a frequency table from a file
static boolean CreateStandardTableFromStream(java.lang.String name, java.io.InputStream in)
          compute a frequency table from an InputStream and save a compacted representation of this table in the system preferences.
static void dumpTable(int[] table)
           
 ch.rgw.compress.HuffmanTree.Node getRootNode()
           
 int[] getTable()
           
static int[] loadTable(java.io.InputStream in)
          Reloads a frequency table as saved by saveTable
 boolean saveTable(java.io.OutputStream out)
          Creates a compacted form of the actual frequency table and saves it into an OutputStream.
static int[] useStandardTable(java.lang.String name)
          Import a compaced frequency table from the system preferences (In windows from the registry HKLM/JavaSoft/Prefs/ch/rgw/tools/Compress/StandardTables, in Linux from ~/.prefs)
static int[] useTable(byte[] in)
          imports a compacted predefined Table
static java.lang.String Version()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

freq

public int[] freq

TextDeutsch

public static byte[] TextDeutsch
Standard table for German text

Constructor Detail

HuffmanTree

public HuffmanTree()

HuffmanTree

public HuffmanTree(byte[] source)
create a Huffman Tree from a given source. Counts the frequency of each byte on the source and constructs the tree accordingly

Parameters:
source - an arbitrary sequence of bytes.

HuffmanTree

public HuffmanTree(int[] frequencyTable)
create a Huffman Tree from a frequency table (which must be an Integer Array of exactly 255 elements)

Parameters:
frequencyTable -
Method Detail

Version

public static java.lang.String Version()

build

public ch.rgw.compress.HuffmanTree.Node build(int[] table)
Build a tree from a frequency table. Ensures that escape and eof are represented in the tree.

Parameters:
table - a field of TABLESIZE ints indicating the frequency od each byte
Returns:
the root node of the newly created tree

constructTable

public static int[] constructTable(byte[] source)
constructs a frequency table from an array of bytes

Parameters:
source - the array to construct the table from

constructTable

public static int[] constructTable(java.io.RandomAccessFile file)
constructs a frequency table from a file


constructTable

public java.io.InputStream constructTable(java.io.InputStream source,
                                          boolean copy)
Construct a frequency table from an InputStream. This will create a temporary file to copy the InputStream in.

Parameters:
source - the Input Stream
Returns:
an InputStream which is a copy of the source Stream, provided to re-Read the same Bytes for the actual compression process.

saveTable

public boolean saveTable(java.io.OutputStream out)
Creates a compacted form of the actual frequency table and saves it into an OutputStream.

Returns:
true on success

loadTable

public static int[] loadTable(java.io.InputStream in)
Reloads a frequency table as saved by saveTable

Returns:
the table

useTable

public static int[] useTable(byte[] in)
imports a compacted predefined Table

Parameters:
in -
Returns:

useStandardTable

public static int[] useStandardTable(java.lang.String name)
Import a compaced frequency table from the system preferences (In windows from the registry HKLM/JavaSoft/Prefs/ch/rgw/tools/Compress/StandardTables, in Linux from ~/.prefs)

Parameters:
name - Name of the table in the registry. If no table with this name is found, the default table (TextDeutsch) is returned.
Returns:
the table

CreateStandardTableFromStream

public static boolean CreateStandardTableFromStream(java.lang.String name,
                                                    java.io.InputStream in)
                                             throws java.lang.Exception
compute a frequency table from an InputStream and save a compacted representation of this table in the system preferences. (To be used later by @see #useStandardTable(String) )

Parameters:
name - name to give the table.
in - InputStream
Returns:
true on success
Throws:
java.lang.Exception

getRootNode

public ch.rgw.compress.HuffmanTree.Node getRootNode()

getTable

public int[] getTable()

dumpTable

public static void dumpTable(int[] table)

checkCompacter

public static boolean checkCompacter()

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis