picture.io
Class ArithOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--picture.io.ArithOutputStream
All Implemented Interfaces:
picture.io.ArithConstants

public class ArithOutputStream
extends java.io.FilterOutputStream
implements picture.io.ArithConstants

Output stream which transforms its data via arithmetic encoding. This implementation is based on ideas of c source code from Mark Nelson. This stream performs an order-0 adaptive arithmetic encoding function. Based on C code from 1987 CACM article by Witten, Neal, and Cleary.


Field Summary
static int CODE_VALUE_BITS
           
static int EOF_SYMBOL
           
static long FIRST_QTR
           
static long HALF
           
static int MAX_FREQUENCY
           
static int NO_OF_CHARS
           
static int NO_OF_SYMBOLS
           
static long THIRD_QTR
           
static long TOP_VALUE
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ArithOutputStream(java.io.OutputStream out)
          Initialize and set output stream.
ArithOutputStream(java.io.OutputStream out, boolean writeEOF)
          Initialize and set output stream.
 
Method Summary
 void close()
          Transforms the cached data and writes it to the underlying output stream, which is closed, too.
 void flush()
          Transforms the cached data and writes it to the underlying output stream, which is flushed, too.
static void main(java.lang.String[] args)
           
 void write(byte[] b, int off, int len)
          Encode and write byte array.
 void write(int b)
          Encode and write byte.
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_OF_CHARS

public static final int NO_OF_CHARS

EOF_SYMBOL

public static final int EOF_SYMBOL

NO_OF_SYMBOLS

public static final int NO_OF_SYMBOLS

CODE_VALUE_BITS

public static final int CODE_VALUE_BITS

TOP_VALUE

public static final long TOP_VALUE

FIRST_QTR

public static final long FIRST_QTR

HALF

public static final long HALF

THIRD_QTR

public static final long THIRD_QTR

MAX_FREQUENCY

public static final int MAX_FREQUENCY
Constructor Detail

ArithOutputStream

public ArithOutputStream(java.io.OutputStream out)
Initialize and set output stream.

ArithOutputStream

public ArithOutputStream(java.io.OutputStream out,
                         boolean writeEOF)
Initialize and set output stream.
Parameters:
out - stream to write to
writeEOF - write special EOF symbol. Set this to false if you know exactly when to stop reading ...
Method Detail

write

public void write(int b)
           throws java.io.IOException
Encode and write byte.
Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - byte to write
Throws:
java.io.IOException -  

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Encode and write byte array. The data is written byte for byte with write(int) to the underlying output stream.
Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - byte array to write
off - starting offset
len - number of bytes to write
Throws:
java.io.IOException -  

flush

public void flush()
           throws java.io.IOException
Transforms the cached data and writes it to the underlying output stream, which is flushed, too.
Overrides:
flush in class java.io.FilterOutputStream
Throws:
IOException. -  

close

public void close()
           throws java.io.IOException
Transforms the cached data and writes it to the underlying output stream, which is closed, too.
Overrides:
close in class java.io.FilterOutputStream
Throws:
IOException. -  

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException