korat.utils.io
Class BitOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by korat.utils.io.BitOutputStream
All Implemented Interfaces:
Closeable, Flushable, IBitWriter

public class BitOutputStream
extends FilterOutputStream
implements IBitWriter

Utility for writing bits to underlying OutputStream

Author:
Aleksandar Milicevic

Field Summary
private  int buff
           
private  int buffSize
           
private static long[] MASKS
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
BitOutputStream(OutputStream out)
           
 
Method Summary
 void flush()
          Flush internal buffers to underlying layer
 void writeBits(long b, int len)
          Writes len bits of the given value b starting from bit offset 0.
 void writeBits(long b, int off, int len)
          Writes len bits of the given value b starting from bit offset off.
 void writeDouble(double x)
          Write given double in 64 bits
 void writeFloat(float x)
          Write given float in 32 bits
 void writeInt(int x)
          Write given int in 32 bits
 void writeLong(long x)
          Write given long in 64 bits
 
Methods inherited from class java.io.FilterOutputStream
close, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MASKS

private static final long[] MASKS

buff

private int buff

buffSize

private int buffSize
Constructor Detail

BitOutputStream

public BitOutputStream(OutputStream out)
Parameters:
out - as per the general contract of the FilterOutputStream
Method Detail

writeBits

public void writeBits(long b,
                      int len)
               throws IOException
Description copied from interface: IBitWriter
Writes len bits of the given value b starting from bit offset 0.

Specified by:
writeBits in interface IBitWriter
Parameters:
b - bits to write
len - number of bits from value b to write
Throws:
IOException - if an I/O error occurs.

writeBits

public void writeBits(long b,
                      int off,
                      int len)
               throws IOException
Description copied from interface: IBitWriter
Writes len bits of the given value b starting from bit offset off.

Specified by:
writeBits in interface IBitWriter
Parameters:
b - bits to write
off - number of bits from the given value b to skip
len - number of bits from the given value b to write starting from off-th bit
Throws:
IOException - if an I/O error occurs.

writeInt

public void writeInt(int x)
              throws IOException
Description copied from interface: IBitWriter
Write given int in 32 bits

Specified by:
writeInt in interface IBitWriter
Parameters:
x - int value to write
Throws:
IOException - if an I/O error occurs.

writeLong

public void writeLong(long x)
               throws IOException
Description copied from interface: IBitWriter
Write given long in 64 bits

Specified by:
writeLong in interface IBitWriter
Parameters:
x - long value to write
Throws:
IOException - if an I/O error occurs.

writeFloat

public void writeFloat(float x)
                throws IOException
Description copied from interface: IBitWriter
Write given float in 32 bits

Specified by:
writeFloat in interface IBitWriter
Parameters:
x - float value to write
Throws:
IOException - if an I/O error occurs.

writeDouble

public void writeDouble(double x)
                 throws IOException
Description copied from interface: IBitWriter
Write given double in 64 bits

Specified by:
writeDouble in interface IBitWriter
Parameters:
x - double value to write
Throws:
IOException - if an I/O error occurs.

flush

public void flush()
           throws IOException
Description copied from interface: IBitWriter
Flush internal buffers to underlying layer

Specified by:
flush in interface Flushable
Specified by:
flush in interface IBitWriter
Overrides:
flush in class FilterOutputStream
Throws:
IOException - if an I/O error occurs.