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

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.ByteAlignedBitDataWriter
Direct Known Subclasses:
BitDataWriter

public class ByteAlignedBitDataWriter
extends Object

Byte aligned data stream writer.

Provides the byte processing during its serialization.

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

Field Summary
protected  OutputStream stream
           
 
Constructor Summary
ByteAlignedBitDataWriter(OutputStream out)
          Constructor with underlied byte output stream.
 
Method Summary
protected  int acquireLength(int length)
           
protected  void checkLength(int limit, int actual)
           
 void close()
          Closes this output stream and releases any system resources associated with this stream.
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(byte[] data, int length)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void writeByte(byte data, int length)
          Writes one byte into an output stream.
 void writeInteger(int data, int length)
          Writes fourth bytes into an output stream.
 void writeLong(long data, int length)
          Writes eights bytes into an output stream.
protected  void writePrimitives(long data, int length)
          Write data into output stream.
 void writeShort(short data, int length)
          Writes two bytes into an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stream

protected OutputStream stream
Constructor Detail

ByteAlignedBitDataWriter

public ByteAlignedBitDataWriter(OutputStream out)
Constructor with underlied byte output stream.

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

writeByte

public void writeByte(byte data,
                      int length)
               throws IOException
Writes one byte into an output stream.

Writes the length bits from specified byte of data to output stream. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) write..() method with same length specified.

Parameters:
data - the data.
length - the number of bits to write (allowed values 1..8).
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 8.
IOException - if an I/O error occurs.
See Also:
write(byte[], int)

writeShort

public void writeShort(short data,
                       int length)
                throws IOException
Writes two bytes into an output stream.

Writes the length bits from specified 2 bytes of data to output stream. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) write..() method with same length specified.

Parameters:
data - the data.
length - the number of bits to write (allowed values 1..16).
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 16.
IOException - if an I/O error occurs.
See Also:
writeByte(byte, int), write(byte[], int)

writeInteger

public void writeInteger(int data,
                         int length)
                  throws IOException
Writes fourth bytes into an output stream.

Writes the length bits from specified 4 bytes of data to output stream. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) write..() method with same length specified.

Parameters:
data - the data.
length - the number of bits to write (allowed values 1..32).
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 32.
IOException - if an I/O error occurs.
See Also:
writeByte(byte, int), writeShort(short, int), write(byte[], int)

writeLong

public void writeLong(long data,
                      int length)
               throws IOException
Writes eights bytes into an output stream.

Writes the length bits from specified 8 bytes of data to output stream. The general contract for this method is that it should have exactly the same effect as the call any allowed (by possible length) write..() method with same length specified.

Parameters:
data - the data.
length - the number of bits to write (allowed values 1..64).
Throws:
IllegalArgumentException - if specified length is below or equals to 0 or greater than 64.
IOException - if an I/O error occurs.
See Also:
writeShort(short, int), writeInteger(int, int), write(byte[], int)

write

public void write(byte[] data,
                  int length)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

The write method of OutputStream calls the write method of one argument on each of the bytes to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters:
data - the data.
length - the number of bits to write.
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

flush

public void flush()
           throws IOException
Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

The flush method of OutputStream does nothing.

Throws:
IOException - if an I/O error occurs.

close

public void close()
           throws IOException
Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

The close method of OutputStream does nothing.

Throws:
IOException - if an I/O error occurs.

acquireLength

protected int acquireLength(int length)

checkLength

protected final void checkLength(int limit,
                                 int actual)

writePrimitives

protected void writePrimitives(long data,
                               int length)
                        throws IOException
Write data into output stream.

Writes length bits from the specified data to output stream. This method designed to provide the network byte ordering for Java primitives: short, int and long. Subclasses of this may override it to provide the other byte ordering.

The general contract for this method is that the bytes in the data are written to the output stream in network order (the standard Java byte ordering) when highest byte is the first byte written and lowest is the last byte written by this operation.

Parameters:
data - the data to be written.
length - the number of bits that should be written.
Throws:
IOException - if an I/O error occurs.


C24 Technologies © 2002-2012: All Rights Reserved.