picture.io
Class ArithInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--picture.io.ArithInputStream
All Implemented Interfaces:
picture.io.ArithConstants

public class ArithInputStream
extends java.io.FilterInputStream
implements picture.io.ArithConstants

Input 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.FilterInputStream
in
 
Constructor Summary
ArithInputStream(java.io.InputStream in)
          Initialize and set input stream.
 
Method Summary
static void main(java.lang.String[] args)
           
 void mark(int readlimit)
          Do nothing.
 boolean markSupported()
           
 int read()
          Reads and transforms a byte from the underlying input stream.
 int read(byte[] b, int off, int len)
          Reads and transforms a byte array from the underlying input stream.
 void reset()
          Do nothing.
 long skip(long n)
          Skips bytes.
 
Methods inherited from class java.io.FilterInputStream
available, close, read
 
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

ArithInputStream

public ArithInputStream(java.io.InputStream in)
Initialize and set input stream.
Method Detail

read

public int read()
         throws java.io.IOException
Reads and transforms a byte from the underlying input stream.
Overrides:
read in class java.io.FilterInputStream
Returns:
tranformed byte or -1 for end of file
Throws:
java.io.IOException -  

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads and transforms a byte array from the underlying input stream. The data is read byte for byte via read() from the underlying input stream.
Overrides:
read in class java.io.FilterInputStream
Parameters:
b - where to write the bytes to
off - starting offset
len - how many bytes to read
Returns:
number of bytes bytes actually read
Throws:
java.io.IOException -  

mark

public void mark(int readlimit)
Do nothing.
Overrides:
mark in class java.io.FilterInputStream

reset

public void reset()
           throws java.io.IOException
Do nothing.
Overrides:
reset in class java.io.FilterInputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class java.io.FilterInputStream
Returns:
false

skip

public long skip(long n)
          throws java.io.IOException
Skips bytes.
Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - how many bytes to skip.
Returns:
number of bytes actually skipped
Throws:
java.io.IOException -  

main

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