biz.c24.io.api.presentation.stream
Class BitDataReader

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.DataReader
      extended by biz.c24.io.api.presentation.stream.ByteAlignedBitDataReader
          extended by biz.c24.io.api.presentation.stream.BitDataReader

public class BitDataReader
extends ByteAlignedBitDataReader

Bit aligned data stream reader.

Provides the byte stream processing as bit sequence.

Version:
$Revision: 10302 $ $Date: 2008-04-02 14:08:09 -0400 (Wed, 02 Apr 2008) $

Nested Class Summary
 
Nested classes/interfaces inherited from class biz.c24.io.api.presentation.stream.DataReader
DataReader.Locator
 
Field Summary
 
Fields inherited from class biz.c24.io.api.presentation.stream.ByteAlignedBitDataReader
buffer, stream
 
Fields inherited from class biz.c24.io.api.presentation.stream.DataReader
count, eof, locator, pos
 
Constructor Summary
BitDataReader(InputStream in)
          Constructs the bit sequence stream with underlied input stream.
 
Method Summary
protected  DataReader.Locator instantiateLocator()
           
 byte[] read(int length)
          Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.
 byte readByte(int length)
          Reades one byte from an input stream.
 int readInteger(int length)
          Reades four bytes from an input stream.
 long readLong(int length)
          Reades eight bytes from an input stream.
protected  long readPrimitives(int length)
           
 short readShort(int length)
          Reades two bytes from an input stream.
 byte readUnsignedByte(int length)
          Reades one byte from an input stream.
 int readUnsignedInteger(int length)
          Reades four bytes from an input stream.
 long readUnsignedLong(int length)
          Reades eight bytes from an input stream.
 short readUnsignedShort(int length)
          Reades two bytes from an input stream.
 void rollback(DataReader.Locator locator)
          See the general contract of the rollback method of DataReader.
 int skip(int n)
          See the general contract of the skip method of DataReader.
 
Methods inherited from class biz.c24.io.api.presentation.stream.ByteAlignedBitDataReader
available, availableBytes, checkLength, checkTheSign, close, compact, fill, startsFrom, updateValue, updateValue
 
Methods inherited from class biz.c24.io.api.presentation.stream.DataReader
ensureOpen, eof, getDataStream, getLocator, getLookAhead, getLookBehind, mark, setLookAhead, setLookBehind, updateLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitDataReader

public BitDataReader(InputStream in)
Constructs the bit sequence stream with underlied input stream.

Parameters:
in - The underlied input stream.
Method Detail

readByte

public byte readByte(int length)
              throws IOException
Reades one byte from an input stream.

Reades the next length bits from input stream and returns the result as byte. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readByte in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..8).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 8.
IOException - if an I/O error occurs.
See Also:
read(int)

readUnsignedByte

public byte readUnsignedByte(int length)
                      throws IOException
Reades one byte from an input stream.

Reades the next length bits from input stream and returns the result as byte. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readUnsignedByte in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..8).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 8.
IOException - if an I/O error occurs.
See Also:
read(int)

readShort

public short readShort(int length)
                throws IOException
Reades two bytes from an input stream.

Reades the next length bits from input stream and returns the result as 2 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readShort in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..16).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 16.
IOException - if an I/O error occurs.
See Also:
readByte(int), read(int)

readUnsignedShort

public short readUnsignedShort(int length)
                        throws IOException
Reades two bytes from an input stream.

Reades the next length bits from input stream and returns the result as 2 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readUnsignedShort in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..16).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 16.
IOException - if an I/O error occurs.
See Also:
readByte(int), read(int)

readInteger

public int readInteger(int length)
                throws IOException
Reades four bytes from an input stream.

Reades the next length bits from input stream and returns the result as 4 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readInteger in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..32).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 32.
IOException - if an I/O error occurs.
See Also:
readShort(int), readByte(int), read(int)

readUnsignedInteger

public int readUnsignedInteger(int length)
                        throws IOException
Reades four bytes from an input stream.

Reades the next length bits from input stream and returns the result as 4 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readUnsignedInteger in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..32).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 32.
IOException - if an I/O error occurs.
See Also:
readShort(int), readByte(int), read(int)

readLong

public long readLong(int length)
              throws IOException
Reades eight bytes from an input stream.

Reades the next length bits from input stream and returns the result as 8 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readLong in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..64).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 64.
IOException - if an I/O error occurs.
See Also:
readShort(int), readByte(int), read(int)

readUnsignedLong

public long readUnsignedLong(int length)
                      throws IOException
Reades eight bytes from an input stream.

Reades the next length bits from input stream and returns the result as 8 bytes. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) read..() method with same length specified.

Overrides:
readUnsignedLong in class ByteAlignedBitDataReader
Parameters:
length - the number of bits to read (allowed values 1..64).
Returns:
the next length bits from input stream.
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 64.
IOException - if an I/O error occurs.
See Also:
readShort(int), readByte(int), read(int)

read

public byte[] read(int length)
            throws IOException
Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.

This method implements the general contract of the corresponding read method of the InputStream class. As an additional convenience, it attempts to read as many bytes as possible by repeatedly invoking the read method of the underlying stream. This iterated read continues until one of the following conditions becomes true:

If the first read on the underlying stream returns -1 to indicate end-of-file then this method returns -1. Otherwise this method returns the number of bytes actually read.

Subclasses of this class are encouraged, but not required, to attempt to read as many bytes as possible in the same fashion.

Overrides:
read in class ByteAlignedBitDataReader
Parameters:
length - number of bits to read.
Returns:
the number of bytes read, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

skip

public int skip(int n)
         throws IOException
See the general contract of the skip method of DataReader.

Overrides:
skip in class ByteAlignedBitDataReader
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.

rollback

public void rollback(DataReader.Locator locator)
See the general contract of the rollback method of DataReader.

Overrides:
rollback in class DataReader
Parameters:
locator - the location of point within data stream to where location should be rolled back.
Throws:
IllegalStateException - If location is out from allowed range.
See Also:
DataReader.mark()

instantiateLocator

protected DataReader.Locator instantiateLocator()
Overrides:
instantiateLocator in class ByteAlignedBitDataReader

readPrimitives

protected long readPrimitives(int length)
                       throws IOException
Overrides:
readPrimitives in class ByteAlignedBitDataReader
Throws:
IOException


C24 Technologies © 2002-2012: All Rights Reserved.