org.freehep.util.io
Class BitOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.freehep.util.io.CompressableOutputStream
              extended by org.freehep.util.io.BitOutputStream
All Implemented Interfaces:
Closeable, Flushable, FinishableOutputStream
Direct Known Subclasses:
ByteOrderOutputStream

public class BitOutputStream
extends CompressableOutputStream
implements FinishableOutputStream

Class to write bits to a Stream, allowing for byte synchronization. Signed, Unsigned, Booleans and Floats can be written.

Version:
$Id: BitOutputStream.java 8584 2006-08-10 23:06:37Z duns $
Author:
Mark Donszelmann, Charles Loomis

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
BitOutputStream(OutputStream out)
          Create a Bit output stream from given stream
 
Method Summary
 void byteAlign()
          A utility to force the next write to be byte-aligned.
 void close()
           
 void finish()
          Finishes the current outputstream (compresses, flushes, caluclates CRC) and writes whatever is left in the buffers, but does not close the stream.
protected  void flushByte()
          A utility method to flush the next byte
static int minBits(float number)
          calculates the minumum number of bits necessary to write number.
static int minBits(long number)
           
static int minBits(long number, boolean signed)
           
 void write(int b)
           
 void writeBitFlag(boolean bit)
          Write a bit to the output stream.
 void writeFBits(float value, int n)
          Write a float value of n-bits to the stream.
 void writeSBits(long value, int n)
          Write a signed value of n-bits to the output stream.
 void writeUBits(long value, int n)
          Write an unsigned value of n-bits to the output stream.
 
Methods inherited from class org.freehep.util.io.CompressableOutputStream
startCompressing, write
 
Methods inherited from class java.io.FilterOutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitOutputStream

public BitOutputStream(OutputStream out)
Create a Bit output stream from given stream

Parameters:
out - stream to write to
Method Detail

write

public void write(int b)
           throws IOException
Overrides:
write in class CompressableOutputStream
Throws:
IOException

finish

public void finish()
            throws IOException
Description copied from interface: FinishableOutputStream
Finishes the current outputstream (compresses, flushes, caluclates CRC) and writes whatever is left in the buffers, but does not close the stream.

Specified by:
finish in interface FinishableOutputStream
Overrides:
finish in class CompressableOutputStream
Throws:
IOException - if write fails

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class CompressableOutputStream
Throws:
IOException

flushByte

protected void flushByte()
                  throws IOException
A utility method to flush the next byte

Throws:
IOException - if write fails

byteAlign

public void byteAlign()
               throws IOException
A utility to force the next write to be byte-aligned.

Throws:
IOException - if write fails

writeBitFlag

public void writeBitFlag(boolean bit)
                  throws IOException
Write a bit to the output stream. A 1-bit is true; a 0-bit is false.

Parameters:
bit - value to write
Throws:
IOException - if write fails

writeSBits

public void writeSBits(long value,
                       int n)
                throws IOException
Write a signed value of n-bits to the output stream.

Parameters:
value - value to write
n - number of bits to write
Throws:
IOException - if write fails

writeFBits

public void writeFBits(float value,
                       int n)
                throws IOException
Write a float value of n-bits to the stream.

Parameters:
value - value to write
n - number of bits to write
Throws:
IOException - if write fails

writeUBits

public void writeUBits(long value,
                       int n)
                throws IOException
Write an unsigned value of n-bits to the output stream.

Parameters:
value - value to write
n - number of bits to write
Throws:
IOException - if write fails

minBits

public static int minBits(float number)
calculates the minumum number of bits necessary to write number.

Parameters:
number - number
Returns:
minimum number of bits to store number

minBits

public static int minBits(long number)
Parameters:
number - value to calculate bits for
Returns:
number of bits needed to store value

minBits

public static int minBits(long number,
                          boolean signed)
Parameters:
number - value to calculate bits for
signed - true if the value if signed (< 0)
Returns:
number of bits needed to store value


Copyright © 2000-2007 FreeHEP. All Rights Reserved.