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

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.ByteAlignedBitDataWriter
      extended by biz.c24.io.api.presentation.stream.BitDataWriter

public class BitDataWriter
extends ByteAlignedBitDataWriter

Bit aligned data stream writer.

Provides the byte stream processing as bit sequence.

Version:
$Revision: 128 $ $Date: 2007-10-29 22:51:58 +0000 (Mon, 29 Oct 2007) $

Constructor Summary
BitDataWriter(OutputStream out)
          Constructs the bit sequence stream with underlied input stream.
 
Method Summary
 void flush()
          Flushes this output stream and forces any buffered output bytes to be written out.
 void write(byte[] data, int length)
          Write byte array into 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.
 void writeShort(short data, int length)
          Writes two bytes into an output stream.
 
Methods inherited from class biz.c24.io.api.presentation.stream.ByteAlignedBitDataWriter
close
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitDataWriter

public BitDataWriter(OutputStream out)
Constructs the bit sequence stream with underlied input stream.

Parameters:
out - The underlied output stream.
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.

Overrides:
writeByte in class ByteAlignedBitDataWriter
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.

Overrides:
writeShort in class ByteAlignedBitDataWriter
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.

Overrides:
writeInteger in class ByteAlignedBitDataWriter
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.

Overrides:
writeLong in class ByteAlignedBitDataWriter
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
Write byte array into output stream.

Writes length bits from the specified byte array to output stream.

The general contract for this method is that the bytes in the array data are written to the output stream in network order (the standard Java byte ordering) when element data[0] is the first byte written and data[length - 1] is the last byte written by this operation.

This method calls the special write method on each of the bytes to be written out. Subclasses are encouraged to override the method to provide an other byte ordering implementation.

The null value is restricted as data value. The allowed values of length is any positive number above the 0.

Overrides:
write in class ByteAlignedBitDataWriter
Parameters:
data - the data to be written.
length - the number of bits to write.
Throws:
NullPointerException - if specified data is null.
IllegalArgumentException - if specified length is below or equals to 0.
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.

Overrides:
flush in class ByteAlignedBitDataWriter
Throws:
IOException - if an I/O error occurs.


Copyright © 2002-2007 IONA Technologies. All Rights Reserved.