com.imagero.uio.io
Class BitInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bycom.imagero.uio.io.BitInputStream

public class BitInputStream
extends java.io.FilterInputStream

adds ability to read streams bitewise and also to read predefined amount of bits every read() call


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
BitInputStream(java.io.InputStream in)
           
 
Method Summary
 int getBitOffset()
           
 int getBitsToRead()
          how much bits is read every read() call (default - 8)
 boolean isInvertBitOrder()
           
 void mark(int readlimit)
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
          Reads data from input stream into an byte array.
 int read(int nbits)
           
 void reset()
           
 void resetBuffer()
          empties bit buffer.
 void setBitsToRead(int bitsToRead)
          set how much bits is read every read() call (max 8)
 void setInvertBitOrder(boolean invertBitOrder)
           
 long skip(long n)
          Skips some bytes from the input stream.
 int skipBits(int n)
           
 int skipToByteBoundary()
           
 
Methods inherited from class java.io.FilterInputStream
available, close, markSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitInputStream

public BitInputStream(java.io.InputStream in)
Method Detail

getBitsToRead

public int getBitsToRead()
how much bits is read every read() call (default - 8)

Returns:

setBitsToRead

public void setBitsToRead(int bitsToRead)
set how much bits is read every read() call (max 8)

Parameters:
bitsToRead -

isInvertBitOrder

public boolean isInvertBitOrder()

setInvertBitOrder

public void setInvertBitOrder(boolean invertBitOrder)

read

public int read()
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(int nbits)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws java.io.IOException
Reads data from input stream into an byte array.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if the EOF has been reached.
Throws:
java.io.IOException - if an I/O error occurs.
java.lang.NullPointerException - if supplied byte array is null

resetBuffer

public void resetBuffer()
empties bit buffer.


skip

public long skip(long n)
          throws java.io.IOException
Skips some bytes from the input stream. If bit buffer is not empty, n - (vbits + 8) / 8 bytes skipped, then buffer is resetted and filled with same amount of bits as it has before skipping.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.

skipBits

public int skipBits(int n)
             throws java.io.IOException
Parameters:
n - bits to skip
Returns:
number of bits skipped
Throws:
java.io.IOException

skipToByteBoundary

public int skipToByteBoundary()
                       throws java.io.IOException
Throws:
java.io.IOException

getBitOffset

public int getBitOffset()

mark

public void mark(int readlimit)

reset

public void reset()
           throws java.io.IOException
Throws:
java.io.IOException