org.freehep.util.io
Class BitOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.freehep.util.io.CompressableOutputStream
-
- org.freehep.util.io.BitOutputStream
-
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, 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.
-
-
Constructor Summary
Constructors Constructor and Description BitOutputStream(java.io.OutputStream out)Create a Bit output stream from given stream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidbyteAlign()A utility to force the next write to be byte-aligned.voidclose()voidfinish()Finishes the current outputstream (compresses, flushes, caluclates CRC) and writes whatever is left in the buffers, but does not close the stream.static intminBits(float number)calculates the minumum number of bits necessary to write number.static intminBits(long number)static intminBits(long number, boolean signed)voidwrite(int b)voidwriteBitFlag(boolean bit)Write a bit to the output stream.voidwriteFBits(float value, int n)Write a float value of n-bits to the stream.voidwriteSBits(long value, int n)Write a signed value of n-bits to the output stream.voidwriteUBits(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
-
-
-
-
Constructor Detail
-
BitOutputStream
public BitOutputStream(java.io.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 java.io.IOException- Overrides:
writein classCompressableOutputStream- Throws:
java.io.IOException
-
finish
public void finish() throws java.io.IOExceptionDescription copied from interface:FinishableOutputStreamFinishes the current outputstream (compresses, flushes, caluclates CRC) and writes whatever is left in the buffers, but does not close the stream.- Specified by:
finishin interfaceFinishableOutputStream- Overrides:
finishin classCompressableOutputStream- Throws:
java.io.IOException- if write fails
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable- Overrides:
closein classCompressableOutputStream- Throws:
java.io.IOException
-
byteAlign
public void byteAlign() throws java.io.IOExceptionA utility to force the next write to be byte-aligned.- Throws:
java.io.IOException- if write fails
-
writeBitFlag
public void writeBitFlag(boolean bit) throws java.io.IOExceptionWrite a bit to the output stream. A 1-bit is true; a 0-bit is false.- Parameters:
bit- value to write- Throws:
java.io.IOException- if write fails
-
writeSBits
public void writeSBits(long value, int n) throws java.io.IOExceptionWrite a signed value of n-bits to the output stream.- Parameters:
value- value to writen- number of bits to write- Throws:
java.io.IOException- if write fails
-
writeFBits
public void writeFBits(float value, int n) throws java.io.IOExceptionWrite a float value of n-bits to the stream.- Parameters:
value- value to writen- number of bits to write- Throws:
java.io.IOException- if write fails
-
writeUBits
public void writeUBits(long value, int n) throws java.io.IOExceptionWrite an unsigned value of n-bits to the output stream.- Parameters:
value- value to writen- number of bits to write- Throws:
java.io.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 forsigned- true if the value if signed (< 0)- Returns:
- number of bits needed to store value
-
-
DMelt 3.0 © DataMelt by jWork.ORG