org.kc7bfi.jflac.io
Class BitInputStream

java.lang.Object
  extended by org.kc7bfi.jflac.io.BitInputStream

public class BitInputStream
extends Object

Bit-wide input stream.

Author:
kc7bfi

Constructor Summary
BitInputStream(InputStream is)
          The constructor.
 
Method Summary
 int bitsLeftForByteAlignment()
          return the number of bits to read to align the byte.
 int getInputBytesUnconsumed()
          return the number of bytes left to read.
 short getReadCRC16()
          return the read CRC-16 value.
 int getTotalBytesRead()
          Total Blurbs read.
 boolean isConsumedByteAligned()
          Test if the Bit Stream consumed bits is byte aligned.
 int peekBitToInt(int val, int bit)
          peek at the next bit and add it to the input integer.
 int peekRawUInt(int bits)
          peek at bits into an unsigned integer without advancing the input stream.
 int readBit()
          read a single bit.
 int readBitToInt(int val)
          read a bit into an integer value.
 long readBitToLong(long val)
          read a bit into a long value.
 void readByteBlockAlignedNoCRC(byte[] val, int nvals)
          Read a block of bytes (aligned) without updating the CRC value.
 int readRawInt(int bits)
          read bits into a signed integer.
 int readRawIntLittleEndian()
          read bits into an unsigned little endian integer.
 int readRawUInt(int bits)
          read bits into an unsigned integer.
 long readRawULong(int bits)
          read bits into an unsigned long.
 void readRiceSignedBlock(int[] vals, int pos, int nvals, int parameter)
          Read a Rice Signal Block.
 int readUnaryUnsigned()
          Read and count the number of zero bits.
 int readUTF8Int(ByteData raw)
          read UTF8 integer.
 long readUTF8Long(ByteData raw)
          read UTF long.
 void reset()
          Reset the bit stream.
 void resetReadCRC16(short seed)
          Reset the read CRC-16 value.
 void skipBitsNoCRC(int bits)
          skip over bits in bit stream without updating CRC.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitInputStream

public BitInputStream(InputStream is)
The constructor.

Parameters:
is - The InputStream to read bits from
Method Detail

reset

public void reset()
Reset the bit stream.


resetReadCRC16

public void resetReadCRC16(short seed)
Reset the read CRC-16 value.

Parameters:
seed - The initial CRC-16 value

getReadCRC16

public short getReadCRC16()
return the read CRC-16 value.

Returns:
The read CRC-16 value

isConsumedByteAligned

public boolean isConsumedByteAligned()
Test if the Bit Stream consumed bits is byte aligned.

Returns:
True of bit stream consumed bits is byte aligned

bitsLeftForByteAlignment

public int bitsLeftForByteAlignment()
return the number of bits to read to align the byte.

Returns:
The number of bits to align the byte

getInputBytesUnconsumed

public int getInputBytesUnconsumed()
return the number of bytes left to read.

Returns:
The number of bytes left to read

skipBitsNoCRC

public void skipBitsNoCRC(int bits)
                   throws IOException
skip over bits in bit stream without updating CRC.

Parameters:
bits - Number of bits to skip
Throws:
IOException - Thrown if error reading from input stream

readBit

public int readBit()
            throws IOException
read a single bit.

Returns:
The bit
Throws:
IOException - Thrown if error reading input stream

readBitToInt

public int readBitToInt(int val)
                 throws IOException
read a bit into an integer value. The bits of the input integer are shifted left and the read bit is placed into bit 0.

Parameters:
val - The integer to shift and add read bit
Returns:
The updated integer value
Throws:
IOException - Thrown if error reading input stream

peekBitToInt

public int peekBitToInt(int val,
                        int bit)
                 throws IOException
peek at the next bit and add it to the input integer. The bits of the input integer are shifted left and the read bit is placed into bit 0.

Parameters:
val - The input integer
bit - The bit to peek at
Returns:
The updated integer value
Throws:
IOException - Thrown if error reading input stream

readBitToLong

public long readBitToLong(long val)
                   throws IOException
read a bit into a long value. The bits of the input long are shifted left and the read bit is placed into bit 0.

Parameters:
val - The long to shift and add read bit
Returns:
The updated long value
Throws:
IOException - Thrown if error reading input stream

readRawUInt

public int readRawUInt(int bits)
                throws IOException
read bits into an unsigned integer.

Parameters:
bits - The number of bits to read
Returns:
The bits as an unsigned integer
Throws:
IOException - Thrown if error reading input stream

peekRawUInt

public int peekRawUInt(int bits)
                throws IOException
peek at bits into an unsigned integer without advancing the input stream.

Parameters:
bits - The number of bits to read
Returns:
The bits as an unsigned integer
Throws:
IOException - Thrown if error reading input stream

readRawInt

public int readRawInt(int bits)
               throws IOException
read bits into a signed integer.

Parameters:
bits - The number of bits to read
Returns:
The bits as a signed integer
Throws:
IOException - Thrown if error reading input stream

readRawULong

public long readRawULong(int bits)
                  throws IOException
read bits into an unsigned long.

Parameters:
bits - The number of bits to read
Returns:
The bits as an unsigned long
Throws:
IOException - Thrown if error reading input stream

readRawIntLittleEndian

public int readRawIntLittleEndian()
                           throws IOException
read bits into an unsigned little endian integer.

Returns:
The bits as an unsigned integer
Throws:
IOException - Thrown if error reading input stream

readByteBlockAlignedNoCRC

public void readByteBlockAlignedNoCRC(byte[] val,
                                      int nvals)
                               throws IOException
Read a block of bytes (aligned) without updating the CRC value.

Parameters:
val - The array to receive the bytes. If null, no bytes are returned
nvals - The number of bytes to read
Throws:
IOException - Thrown if error reading input stream

readUnaryUnsigned

public int readUnaryUnsigned()
                      throws IOException
Read and count the number of zero bits.

Returns:
The number of zero bits read
Throws:
IOException - Thrown if error reading input stream

readRiceSignedBlock

public void readRiceSignedBlock(int[] vals,
                                int pos,
                                int nvals,
                                int parameter)
                         throws IOException
Read a Rice Signal Block.

Parameters:
vals - The values to be returned
pos - The starting position in the vals array
nvals - The number of values to return
parameter - The Rice parameter
Throws:
IOException - On read error

readUTF8Int

public int readUTF8Int(ByteData raw)
                throws IOException
read UTF8 integer. on return, if *val == 0xffffffff then the utf-8 sequence was invalid, but the return value will be true

Parameters:
raw - The raw bytes read (output). If null, no bytes are returned
Returns:
The integer read
Throws:
IOException - Thrown if error reading input stream

readUTF8Long

public long readUTF8Long(ByteData raw)
                  throws IOException
read UTF long. on return, if *val == 0xffffffffffffffff then the utf-8 sequence was invalid, but the return value will be true

Parameters:
raw - The raw bytes read (output). If null, no bytes are returned
Returns:
The long read
Throws:
IOException - Thrown if error reading input stream

getTotalBytesRead

public int getTotalBytesRead()
Total Blurbs read.

Returns:
Returns the total blurbs read.


Copyright © 2004-2011. All Rights Reserved.