EXIficient

com.siemens.ct.exi.io
Class BitOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.siemens.ct.exi.io.BitOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class BitOutputStream
extends java.io.OutputStream

Write bits and bytes to an underlying output stream.

Version:
0.4.20081010
Author:
Daniel.Peintner.EXT@siemens.com, Joerg.Heuer@siemens.com

Field Summary
static int BITS_IN_BYTE
           
 
Constructor Summary
BitOutputStream(java.io.OutputStream ostream)
          Constructs an instance of this class.
 
Method Summary
 void align()
          If there are some unwritten bits, pad them if necessary and write them out.
 void flush()
          If there are some unwritten bits, pad them if necessary and write them out.
 int getBitsInBuffer()
          Returns the number of bits that haven't been flushed.
 java.io.OutputStream getUnderlyingOutputStream()
          Returns a reference to underlying output stream.
 boolean isByteAligned()
          Returns true if stream is on a byte boundary, i.e. if no bits have been buffered since the last byte was written to underlying stream.
 void write(int b)
           
 void writeBit0()
          Write a single bit 0.
 void writeBit1()
          Write a single bit 1.
 void writeBits(int b, int n)
          Write the n least significant bits of parameter b starting with the most significant, i.e. from left to right.
 
Methods inherited from class java.io.OutputStream
close, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BITS_IN_BYTE

public static final int BITS_IN_BYTE
See Also:
Constant Field Values
Constructor Detail

BitOutputStream

public BitOutputStream(java.io.OutputStream ostream)
Constructs an instance of this class.

Method Detail

getUnderlyingOutputStream

public java.io.OutputStream getUnderlyingOutputStream()
Returns a reference to underlying output stream.


isByteAligned

public boolean isByteAligned()
Returns true if stream is on a byte boundary, i.e. if no bits have been buffered since the last byte was written to underlying stream.


getBitsInBuffer

public int getBitsInBuffer()
Returns the number of bits that haven't been flushed. When the buffer is full, it is automatically flushed, so the number returned by this method is in [0, 7].


flush

public void flush()
           throws java.io.IOException
If there are some unwritten bits, pad them if necessary and write them out. Note that this method does not flush the underlying stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

align

public void align()
           throws java.io.IOException
If there are some unwritten bits, pad them if necessary and write them out.

Throws:
java.io.IOException

writeBit0

public void writeBit0()
               throws java.io.IOException
Write a single bit 0.

Throws:
java.io.IOException

writeBit1

public void writeBit1()
               throws java.io.IOException
Write a single bit 1.

Throws:
java.io.IOException

writeBits

public void writeBits(int b,
                      int n)
               throws java.io.IOException
Write the n least significant bits of parameter b starting with the most significant, i.e. from left to right.

Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

EXIficient