public class BitOutputStream extends Object
Constructor and Description |
---|
BitOutputStream()
Empty constructor
|
BitOutputStream(OutputStream os)
Constructs an instance of the class for a given OutputSTream
|
Modifier and Type | Method and Description |
---|---|
void |
append(byte[] toAppend,
int len)
Appends a byte array to the current stream.
|
void |
append(byte[] toAppend,
int len,
byte newByte,
int bitswritten)
Appends a byte array to the current stream, where the last byte is not fully written
Flushes the current int, the buffer and then writes the new sequence of bytes.
|
void |
close()
Closes the BitOutputStream.
|
byte |
getBitOffset()
Returns the bit offset in the last byte.
|
long |
getByteOffset()
Returns the byte offset of the stream.
|
void |
padAndFlush()
Pads the current byte and writes the current int into the buffer.
|
int |
writeBinary(int len,
int x)
Writes an integer in binary format to the stream.
|
int |
writeDelta(int x)
Writes an integer x into the stream using delta encoding.
|
int |
writeGamma(int x)
Writes an integer x into the stream using gamma encoding.
|
int |
writeGolomb(int x,
int b)
Writes and integer x into the stream using golomb coding.
|
int |
writeInt(int x,
int len)
Writes an integer x into the underlying OutputStream.
|
int |
writeInterpolativeCode(int[] data,
int offset,
int len,
int lo,
int hi)
Writes a sequence of integers using interpolative coding.
|
int |
writeMinimalBinary(int x,
int b)
Writes an integer x using minimal binary encoding, given an upper bound.
|
int |
writeSkewedGolomb(int x,
int b)
Writes and integer x into the stream using skewed-golomb coding.
|
int |
writeUnary(int x)
Writes an integer x using unary encoding.
|
public BitOutputStream()
public BitOutputStream(OutputStream os) throws IOException
os
- the java.io.OutputStream used for writtingIOException
- if an I/O error occurspublic void append(byte[] toAppend, int len) throws IOException
toAppend
- byte[] it is going to be written to the stream.len
- length in bytes of the byte buffer (number of elements of the array).IOException
- if an I/O exception occurs.public void append(byte[] toAppend, int len, byte newByte, int bitswritten) throws IOException
toAppend
- byte[] it is going to be written to the stream.len
- length in bytes of the byte buffer (number of elements of the array).newByte
- last byte (the one not fully written)bitswritten
- number of bits written in the last byteIOException
- if an I/O exception occurs.public void close() throws IOException
IOException
- if an I/O error occurs when closing the underlying OutputStreampublic byte getBitOffset()
public long getByteOffset()
public void padAndFlush() throws IOException
IOException
- if an I/O error occurs.public int writeBinary(int len, int x) throws IOException
len
- size in bits of the number.x
- the integer to write.IOException
- if an I/O error occurs.public int writeDelta(int x) throws IOException
x
- the int number to writeIOException
- if an I/O error occurs.public int writeGamma(int x) throws IOException
x
- the int number to writeIOException
- if an I/O error occurs.public int writeGolomb(int x, int b) throws IOException
x
- the number to writeb
- the parameter for golomb codingIOException
- if and I/O error occurspublic int writeInt(int x, int len) throws IOException
x
- the int to writelen
- length of the int in bitsIOException
- if an I/O error occurs.public int writeInterpolativeCode(int[] data, int offset, int len, int lo, int hi) throws IOException
data
- the vector containing the integer sequence.offset
- the offset into data
where the sequence starts.len
- the number of integers to code.lo
- a lower bound (must be smaller than or equal to the first integer in the sequence).hi
- an upper bound (must be greater than or equal to the last integer in the sequence).IOException
- if an I/O error occurs.public int writeMinimalBinary(int x, int b) throws IOException
x
- the number to writeb
- and strict bound for x
IOException
- if an I/O error occurs.public int writeSkewedGolomb(int x, int b) throws IOException
v = (b, 2b, 4b, ... , 2^i b, ...)
.x
is coded as unary(k+1)
where k
is the index
sum(i=0)(k) v_i < x <= sum(i=0)(k+1)
log(v_k)
bits in binary. k = log(x/b + 1)
and sum_i = b(2^n -1)
(geometric progression)), so
if lower = ceil(x/b) -> lower = 2^i * b -> i = log(ceil(x/b)) + 1
the remainder x - sum_i 2^i*b - 1 = x - b(2^n - 1) - 1
is coded with floor(log(v_k))
bits
x
- the number to writeb
- the parameter for golomb codingIOException
- if and I/O error occurspublic int writeUnary(int x) throws IOException
x
- the number to writeIOException
- if an I/O error occurs.