org.freehep.util.io
Class BitInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.freehep.util.io.DecompressableInputStream
          extended by org.freehep.util.io.BitInputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
ByteOrderInputStream

public class BitInputStream
extends DecompressableInputStream

Class to read bits from a Stream, allowing for byte synchronization. Signed, Unsigned, Booleans and Floats can be read.

Version:
$Id: BitInputStream.java 8584 2006-08-10 23:06:37Z duns $
Author:
Mark Donszelmann, Charles Loomis

Field Summary
protected static int[] BIT_MASK
           
protected static int[] FIELD_MASK
           
protected static int MASK_SIZE
           
protected static int ONES
           
protected static int ZERO
           
 
Constructor Summary
BitInputStream(InputStream in)
          Create a Bit input stream from viven input
 
Method Summary
 void byteAlign()
          A utility to force the next read to be byte-aligned.
protected  void fetchByte()
          A utility method to fetch the next byte in preparation for constructing a bit field.
 boolean readBitFlag()
          Read a bit from the input stream and interpret this as a boolean value.
 float readFBits(int n)
          Read a float value of n-bits from the stream.
 long readSBits(int n)
          Read a signed value of n-bits from the input stream.
 long readUBits(int n)
          Read an unsigned value of n-bits from the input stream.
 
Methods inherited from class org.freehep.util.io.DecompressableInputStream
read, skip, startDecompressing
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, read, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASK_SIZE

protected static final int MASK_SIZE
See Also:
Constant Field Values

ZERO

protected static final int ZERO
See Also:
Constant Field Values

ONES

protected static final int ONES
See Also:
Constant Field Values

BIT_MASK

protected static final int[] BIT_MASK

FIELD_MASK

protected static final int[] FIELD_MASK
Constructor Detail

BitInputStream

public BitInputStream(InputStream in)
Create a Bit input stream from viven input

Parameters:
in - stream to read from
Method Detail

fetchByte

protected void fetchByte()
                  throws IOException
A utility method to fetch the next byte in preparation for constructing a bit field. There is no protection for this method; ensure that it is only called when a byte must be fetched.

Throws:
IOException - if read fails

byteAlign

public void byteAlign()
A utility to force the next read to be byte-aligned.


readBitFlag

public boolean readBitFlag()
                    throws IOException
Read a bit from the input stream and interpret this as a boolean value. A 1-bit is true; a 0-bit is false.

Returns:
true if read bit was 1
Throws:
IOException - if read fails

readSBits

public long readSBits(int n)
               throws IOException
Read a signed value of n-bits from the input stream.

Parameters:
n - number of bits to read
Returns:
value made up of read bits
Throws:
IOException - if read fails

readFBits

public float readFBits(int n)
                throws IOException
Read a float value of n-bits from the stream.

Parameters:
n - number of bits to read
Returns:
value made up of read bits
Throws:
IOException - if read fails

readUBits

public long readUBits(int n)
               throws IOException
Read an unsigned value of n-bits from the input stream.

Parameters:
n - number of bits to read
Returns:
value made up of read bits
Throws:
IOException - if read fails


Copyright © 2000-2007 FreeHEP. All Rights Reserved.