|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.io.Node | +--sam.io.Huffman
Implementation of the auto-adaptive Huffman-tree coding input/output-streams with variable pattern length. This allows for transparent Huffman input/output filtering, like in
for compression and similarlyInputStream source = new FileInputStream("foo.dat"); OutputStream target = new Huffman8().output( new FileOutpuStream("bar.dat") );
InputStream source = new Huffman8().input( new FileInputStream("bar.dat") ); OutputStream target = new FileOutpuStream("foo.dat");
input(java.io.InputStream)
,
output(java.io.OutputStream)
,
Huffman.Leaf
Nested Class Summary | |
protected class |
Huffman.Leaf
Special Node representing a leaf. |
protected class |
Huffman.LeafInputStream
Class for reading leaves from an Huffman-compressed InputStream |
protected class |
Huffman.LeafOutputStream
Class for writing Huffman-compressed leaves to an OutputStream |
Constructor Summary | |
protected |
Huffman(int patternWidth)
Builds a new generic Huffman tree of specified pattern width. |
protected |
Huffman(int patternWidth,
int granularity)
Creates a new well-balanced Huffman tree. |
Method Summary | |
protected Huffman.Leaf |
get(int value)
Gets the leaf coding for specified value. |
abstract java.io.InputStream |
input(java.io.InputStream encodedStream)
Stream for decoding huffman-encoded data |
boolean |
isLeaf()
Wether this node is a pure leaf, i.e. |
int |
longestPath()
|
static void |
main(java.lang.String[] args)
Main executable code. |
int |
numberOfLeaves()
|
int |
numberOfNodes()
|
java.util.Enumeration |
ordered()
Gets the enumeration of all nodes that are lighter than this node in decreasing order. |
abstract java.io.OutputStream |
output(java.io.OutputStream encodedStream)
Stream for encoding 8 bits huffman-encoded data |
float |
ratio()
|
void |
reset()
Resets the Huffman tree into a fully well-balanced one. |
int |
shortestPath()
|
java.lang.String |
toString()
Gets a formatted representation of this huffman tree. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected Huffman(int patternWidth)
patternWidth
- the pattern width.
This can be any positive integer up to 32, but for
obvious reasons multiples of 8 shall be of wider use.protected Huffman(int patternWidth, int granularity)
Each of the numberOfPatterns
patterns is initially weighted by 1.
This is an implementation requirement: a node is required to be strictly heavier than any of its sons,
which would not be granted in case of zero-weighted leaves.
granularity
- the granularity of the frequency updates. Higher means faster but less accurate (and thus
lower compression ratios). In particular, a sequence of at most granularity
consecutive bytes will
not be compressed.patternWidth
- the pattern width.
This can be any positive integer up to 32, but for
obvious reasons multiples of 8 shall be of wider use.Method Detail |
public static void main(java.lang.String[] args)
java sam.Huffman {+|-}{8|16} input output
Warning: 16-bits [en|de]coding is extremly slow !
public abstract java.io.InputStream input(java.io.InputStream encodedStream)
public abstract java.io.OutputStream output(java.io.OutputStream encodedStream)
public int numberOfLeaves()
public int numberOfNodes()
public int shortestPath()
public int longestPath()
public float ratio()
public void reset()
protected Huffman.Leaf get(int value)
value
.Huffman.Leaf.oneMore()
public java.lang.String toString()
toString
in class sam.io.Node
public java.util.Enumeration ordered()
Huffman
instance.
public boolean isLeaf()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |