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

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.DataReader
      extended by biz.c24.io.api.presentation.stream.ByteAlignedBitDataReader
Direct Known Subclasses:
BitDataReader

public class ByteAlignedBitDataReader
extends DataReader

Byte aligned data stream reader.

Provides the byte processing during its deserialization.

Version:
$Revision: 16508 $ $Date: 2010-02-01 11:01:50 -0500 (Mon, 01 Feb 2010) $

Nested Class Summary
 
Nested classes/interfaces inherited from class biz.c24.io.api.presentation.stream.DataReader
DataReader.Locator
 
Field Summary
protected  byte[] buffer
          The internal buffer array where the data is stored.
protected  InputStream stream
          Underlied byte stream.
 
Fields inherited from class biz.c24.io.api.presentation.stream.DataReader
count, eof, locator, pos
 
Constructor Summary
ByteAlignedBitDataReader(InputStream in)
          Constructor with underlied byte input stream.
 
Method Summary
 int available()
          Returns the number of bits that can be read from this input stream.
 int availableBytes()
          Returns the number of bytes that can be read from this input stream.
protected  void checkLength(int limit, int actual)
           
protected  int checkTheSign(long result, int length)
           
 void close()
          Closes this input stream and releases any system resources associated with it.
protected  void compact(int from, int requested)
          Compacts the data in the internal buffer.
protected  int fill(int requested)
          Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks.
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.
 int skip(int n)
          See the general contract of the skip method of DataReader.
 int startsFrom(String[] sign)
          Check wether the byte stream equals to specified str bytes.
protected  void updateValue(byte[] result, int idx, byte value)
           
protected  long updateValue(long result, int idx, byte value)
           
 
Methods inherited from class biz.c24.io.api.presentation.stream.DataReader
ensureOpen, eof, getDataStream, getLocator, getLookAhead, getLookBehind, mark, rollback, setLookAhead, setLookBehind, updateLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stream

protected InputStream stream
Underlied byte stream.


buffer

protected byte[] buffer
The internal buffer array where the data is stored. When necessary, it may be replaced by another array of a different size.

Constructor Detail

ByteAlignedBitDataReader

public ByteAlignedBitDataReader(InputStream in)
Constructor with underlied byte input stream.

Parameters:
in - the underlying input stream.
Throws:
IllegalArgumentException - if underlying input stream is NULL.
Method Detail

close

public void close()
           throws IOException
Closes this input stream and releases any system resources associated with it.

Specified by:
close in class DataReader
Throws:
IOException - if an I/O error occurs.

available

public int available()
Returns the number of bits that can be read from this input stream.

Overrides:
available in class DataReader
Returns:
the number of bits that can be read from this input stream.
See Also:
FilterInputStream.in

availableBytes

public int availableBytes()
Returns the number of bytes that can be read from this input stream.

Returns:
the number of bytes that can be read from this input stream.

startsFrom

public int startsFrom(String[] sign)
               throws IOException
Check wether the byte stream equals to specified str bytes.

Parameters:
sign - The charachter sequence against that the equality is checked.
Returns:
true if byte stream is equals to specified strinf, false - otherwise.
Throws:
IOException - If an I/O error occurs.

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.

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.

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.

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.

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.

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.

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.

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.

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)

readPrimitives

protected long readPrimitives(int length)
                       throws IOException
Throws:
IOException

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.

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 DataReader
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.

instantiateLocator

protected DataReader.Locator instantiateLocator()

fill

protected int fill(int requested)
            throws IOException
Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks. Assumes that it is being called by a synchronized method. This method also assumes that all data has already been read in, hence pos > count.

Specified by:
fill in class DataReader
Parameters:
requested - The requested length of data in bytes.
Returns:
the number of bytes that were actually readed into internal buffer.
Throws:
IOException - If read the underlied input stream failed.

compact

protected void compact(int from,
                       int requested)
                throws IOException
Description copied from class: DataReader
Compacts the data in the internal buffer.

Provides the efficient heap using. It is called any time when internal buffer is near to filled and may be compacted due current limit values.

Specified by:
compact in class DataReader
Parameters:
from - The pointer in buffer up to which data may be marked as invalidated.
requested - the number of bytes that should stay in buffer in any way.
Throws:
IOException - If unexpected I/O error happends.

checkTheSign

protected int checkTheSign(long result,
                           int length)

updateValue

protected void updateValue(byte[] result,
                           int idx,
                           byte value)

updateValue

protected long updateValue(long result,
                           int idx,
                           byte value)

checkLength

protected final void checkLength(int limit,
                                 int actual)


C24 Technologies © 2002-2012: All Rights Reserved.