public class BitOutputStream extends OutputStream
| Modifier and Type | Field and Description |
|---|---|
static int |
BITS_IN_BYTE |
protected int |
buffer
Internal buffer represented as an int.
|
protected int |
capacity
Unused capacity of the internal buffer in bits.
|
protected int |
len
Fully-written bytes
|
| Constructor and Description |
|---|
BitOutputStream(OutputStream ostream)
Constructs an instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
protected void |
flushBuffer()
If buffer is full, write it out and reset internal state.
|
int |
getBitsInBuffer()
Returns the number of bits that haven't been flushed.
|
int |
getLength()
Returns the number of bytes written.
|
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) |
protected void |
writeBit(int b)
Write the least significant bit of parameter b into the internal buffer,
flushing it if necessary.
|
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.
|
protected void |
writeDirectByte(int b)
Ignore current buffer, and write a byte directly to the underlying
stream.
|
protected void |
writeDirectBytes(byte[] b,
int off,
int len)
Ignore current buffer, and write a sequence of bytes directly to the
underlying stream.
|
close, write, writepublic static final int BITS_IN_BYTE
protected int buffer
protected int capacity
protected int len
public BitOutputStream(OutputStream ostream)
ostream - output streampublic OutputStream getUnderlyingOutputStream()
public int getLength()
protected void flushBuffer()
throws IOException
IOException - IO exceptionpublic boolean isByteAligned()
public int getBitsInBuffer()
public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void align()
throws IOException
IOException - IO exceptionpublic void writeBit0()
throws IOException
IOException - IO exceptionpublic void writeBit1()
throws IOException
IOException - IO exceptionprotected void writeBit(int b)
throws IOException
b - bitIOException - IO exceptionpublic void writeBits(int b,
int n)
throws IOException
b - bitsn - number of bitsIOException - IO exceptionprotected void writeDirectByte(int b)
throws IOException
b - byteIOException - IO exceptionprotected void writeDirectBytes(byte[] b,
int off,
int len)
throws IOException
b - byte arrayoff - byte array offsetlen - byte array lengthIOException - IO exceptionpublic void write(int b)
throws IOException
write in class OutputStreamIOExceptionCopyright © 2018 Siemens AG. All rights reserved.