public class DebugOutputBitStream extends OutputBitStream
This class can be used to wrap an output bit stream. The semantics of the resulting write operations is unchanged, but each operation will be logged.
To simplify the output, some operations have a simplified representation. In particular:
flush();
position();
close();
avail, buffer, DEFAULT_BUFFER_SIZE, DELTA, fileChannel, free, GAMMA, MAX_PRECOMPUTED, os, pos, position, repositionableStream, SHIFTED_GAMMA, wrapping, ZETA_3| Constructor and Description |
|---|
DebugOutputBitStream(OutputBitStream obs)
Creates a new debug output bit stream wrapping a given output bit stream and logging on standard error.
|
DebugOutputBitStream(OutputBitStream obs,
PrintStream pw)
Creates a new debug output bit stream wrapping a given output bit stream and logging on a given writer.
|
| Modifier and Type | Method and Description |
|---|---|
int |
align()
Aligns the stream.
|
void |
close()
Closes the bit stream.
|
void |
flush()
Flushes the bit stream.
|
void |
position(long position)
Sets this stream bit position, if it is based on a
RepositionableStream or on a FileChannel. |
long |
write(byte[] bits,
long len)
Writes a sequence of bits.
|
int |
writeBit(boolean bit)
Writes a bit.
|
int |
writeBit(int bit)
Writes a bit.
|
int |
writeDelta(int x)
Writes a natural number in δ coding.
|
int |
writeGamma(int x)
Writes a natural number in γ coding.
|
int |
writeGolomb(int x,
int b)
Writes a natural number in Golomb coding.
|
int |
writeGolomb(int x,
int b,
int log2b)
Writes a natural number in Golomb coding.
|
int |
writeInt(int x,
int len)
Writes a fixed number of bits from an integer.
|
int |
writeLong(long x,
int len)
Writes a fixed number of bits from a long.
|
int |
writeLongDelta(long x)
Writes a long natural number in δ coding.
|
int |
writeLongGamma(long x)
Writes a long natural number in γ coding.
|
long |
writeLongGolomb(long x,
long b)
Writes a long natural number in Golomb coding.
|
long |
writeLongGolomb(long x,
long b,
int log2b)
Writes a long natural number in Golomb coding.
|
int |
writeLongMinimalBinary(long x,
long b)
Writes a long natural number in a limited range using a minimal binary coding.
|
int |
writeLongMinimalBinary(long x,
long b,
int log2b)
Writes a long natural number in a limited range using a minimal binary coding.
|
int |
writeLongNibble(long x)
Writes a long natural number in variable-length nibble coding.
|
long |
writeLongSkewedGolomb(long x,
long b)
Writes a long natural number in skewed Golomb coding.
|
long |
writeLongUnary(long x)
Writes a long natural number in unary coding.
|
int |
writeLongZeta(long x,
int k)
Writes a long natural number in ζ coding.
|
int |
writeMinimalBinary(int x,
int b)
Writes a natural number in a limited range using a minimal binary coding.
|
int |
writeMinimalBinary(int x,
int b,
int log2b)
Writes a natural number in a limited range using a minimal binary coding.
|
int |
writeNibble(int x)
Writes a natural number in variable-length nibble coding.
|
int |
writeSkewedGolomb(int x,
int b)
Writes a natural number in skewed Golomb coding.
|
int |
writeUnary(int x)
Writes a natural number in unary coding.
|
int |
writeZeta(int x,
int k)
Writes a natural number in ζ coding.
|
long |
writtenBits()
Returns the number of bits written to this bit stream.
|
void |
writtenBits(long writtenBits)
Sets the number of bits written to this bit stream.
|
write, write, writeByteOffset, writeLongShiftedGamma, writeShiftedGammapublic DebugOutputBitStream(OutputBitStream obs, PrintStream pw)
obs - the output bit stream to wrap.pw - a print stream that will receive the logging data.public DebugOutputBitStream(OutputBitStream obs)
obs - the output bit stream to wrap.public void flush()
throws IOException
OutputBitStreamThis method will align the stream, write the bit buffer, empty the
byte buffer and delegate to the OutputStream.flush() method of
the underlying output stream.
This method is provided so that users of this class can easily wrap
repositionable streams (for instance, file-based streams, which can be
repositioned using the underlying FileChannel).
It is guaranteed that after calling this method the underlying stream can be repositioned, and that the next write to the underlying output stream will start with the content of the first write method called afterwards.
flush in interface Flushableflush in class OutputBitStreamIOExceptionpublic void close()
throws IOException
OutputBitStreamclose in interface Closeableclose in interface AutoCloseableclose in class OutputBitStreamIOExceptionpublic long writtenBits()
OutputBitStreamwrittenBits in class OutputBitStreampublic void writtenBits(long writtenBits)
OutputBitStreamThis method is provided so that, for instance, the
user can reset via writtenBits(0) the written-bits count
after a OutputBitStream.flush().
writtenBits in class OutputBitStreamwrittenBits - the new value for the number of bits written so far.public int align()
throws IOException
OutputBitStreamalign in class OutputBitStreamIOExceptionpublic void position(long position)
throws IOException
OutputBitStreamRepositionableStream or on a FileChannel.
Given an underlying stream that implements RepositionableStream or that can provide a FileChannel via the getChannel() method,
a call to this method has the same semantics of a OutputBitStream.flush(),
followed by a call to position(position / 8) on
the byte stream. Currently there is no clean, working way of supporting
out-of-byte-boundary positioning.
position in class OutputBitStreamposition - the new position expressed as a bit offset; it must be byte-aligned.IOExceptionFileChannel.position(long)public long write(byte[] bits,
long len)
throws IOException
OutputBitStreamwrite in class OutputBitStreambits - a vector containing the bits to be written.len - a bit length.len).IOExceptionpublic int writeBit(boolean bit)
throws IOException
OutputBitStreamwriteBit in class OutputBitStreambit - a bit.IOExceptionpublic int writeBit(int bit)
throws IOException
OutputBitStreamwriteBit in class OutputBitStreambit - a bit.IOExceptionpublic int writeInt(int x,
int len)
throws IOException
OutputBitStreamwriteInt in class OutputBitStreamx - an integer.len - a bit length; this many lower bits of the first argument will be written
(the most significant bit first).len).IOExceptionpublic int writeLong(long x,
int len)
throws IOException
OutputBitStreamwriteLong in class OutputBitStreamx - a long.len - a bit length; this many lower bits of the first argument will be written
(the most significant bit first).len).IOExceptionpublic int writeUnary(int x)
throws IOException
OutputBitStreamThe unary coding of a natural number n is given by 0n1.
writeUnary in class OutputBitStreamx - a natural number.IOExceptionpublic long writeLongUnary(long x)
throws IOException
OutputBitStreamwriteLongUnary in class OutputBitStreamx - a long natural number.IOExceptionOutputBitStream.writeUnary(int)public int writeGamma(int x)
throws IOException
OutputBitStreamThe γ coding of a positive number of k bits is obtained writing k-1 in unary, followed by the lower k-1 bits of the number. The coding of a natural number is obtained by adding one and coding.
writeGamma in class OutputBitStreamx - a natural number.IOExceptionpublic int writeLongGamma(long x)
throws IOException
OutputBitStreamwriteLongGamma in class OutputBitStreamx - a long natural number.IOExceptionOutputBitStream.writeGamma(int)public int writeDelta(int x)
throws IOException
OutputBitStreamwriteDelta in class OutputBitStreamx - a natural number.IOExceptionpublic int writeLongDelta(long x)
throws IOException
OutputBitStreamwriteLongDelta in class OutputBitStreamx - a long natural number.IOExceptionOutputBitStream.writeDelta(int)public int writeMinimalBinary(int x,
int b)
throws IOException
OutputBitStreamA minimal binary code is an optimal code for the uniform distribution. This method uses an optimal code in which shorter words are assigned to smaller integers.
writeMinimalBinary in class OutputBitStreamx - a natural number.b - a strict upper bound for x.IOExceptionpublic int writeMinimalBinary(int x,
int b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeMinimalBinary(int,int) because it does not
have to compute log2b.writeMinimalBinary in class OutputBitStreamx - a natural number.b - a strict upper bound for x.log2b - the floor of the base-2 logarithm of the bound.IOExceptionOutputBitStream.writeMinimalBinary(int, int)public int writeLongMinimalBinary(long x,
long b)
throws IOException
OutputBitStreamwriteLongMinimalBinary in class OutputBitStreamx - a natural number.b - a strict upper bound for x.IOExceptionOutputBitStream.writeMinimalBinary(int, int)public int writeLongMinimalBinary(long x,
long b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeLongMinimalBinary(long,long) because it does not
have to compute log2b.writeLongMinimalBinary in class OutputBitStreamx - a long natural number.b - a strict upper bound for x.log2b - the floor of the base-2 logarithm of the bound.IOExceptionOutputBitStream.writeMinimalBinary(int, int)public int writeGolomb(int x,
int b)
throws IOException
OutputBitStreamGolomb coding with modulo b writes a natural number x as the quotient of the division of x and b in unary, followed by the remainder in minimal binary code.
This method implements also the case in which b is 0: in this case,
the argument x may only be zero, and nothing will be written.
writeGolomb in class OutputBitStreamx - a natural number.b - the modulus for the coding.IOExceptionpublic int writeGolomb(int x,
int b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeGolomb(int,int) because it does not
have to compute log2b.writeGolomb in class OutputBitStreamx - a natural number.b - the modulus for the coding.log2b - the floor of the base-2 logarithm of the coding modulus (it is irrelevant when b is zero).IOExceptionOutputBitStream.writeGolomb(int, int)public long writeLongGolomb(long x,
long b)
throws IOException
OutputBitStreamwriteLongGolomb in class OutputBitStreamx - a long natural number.b - the modulus for the coding.IOExceptionOutputBitStream.writeGolomb(int, int)public long writeLongGolomb(long x,
long b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeLongGolomb(long,long) because it does not
have to compute log2b.writeLongGolomb in class OutputBitStreamx - a long natural number.b - the modulus for the coding.log2b - the floor of the base-2 logarithm of the coding modulus (it is irrelevant when b is zero).IOExceptionOutputBitStream.writeGolomb(int, int)public int writeSkewedGolomb(int x,
int b)
throws IOException
OutputBitStreamThis method implements also the case in which b is 0: in this case,
the argument x may only be zero, and nothing will be written.
writeSkewedGolomb in class OutputBitStreamx - a natural number.b - the modulus for the coding.IOExceptionpublic long writeLongSkewedGolomb(long x,
long b)
throws IOException
OutputBitStreamThis method implements also the case in which b is 0: in this case,
the argument x may only be zero, and nothing will be written.
writeLongSkewedGolomb in class OutputBitStreamx - a long natural number.b - the modulus for the coding.IOExceptionOutputBitStream.writeSkewedGolomb(int, int)public int writeZeta(int x,
int k)
throws IOException
OutputBitStreamζ coding (with modulo k) records positive numbers in the intervals [1,2k-1],[2k,2k+1-1],…,[2hk,2(h+1)k-1] by coding h in unary, followed by a minimal binary coding of the offset in the interval. The coding of a natural number is obtained by adding one and coding.
ζ codes were defined by Paolo Boldi and Sebastiano Vigna in “Codes for the World−Wide Web”, Internet Math., 2(4):405-427, 2005. The paper contains also a detailed analysis.
writeZeta in class OutputBitStreamx - a natural number.k - the shrinking factor.IOExceptionpublic int writeLongZeta(long x,
int k)
throws IOException
OutputBitStreamwriteLongZeta in class OutputBitStreamx - a long natural number.k - the shrinking factor.IOExceptionOutputBitStream.writeZeta(int, int)public int writeNibble(int x)
throws IOException
OutputBitStreamVariable-length nibble coding records a natural number by padding its binary representation to the left using zeroes, until its length is a multiple of three. Then, the resulting string is broken in blocks of 3 bits, and each block is prefixed with a bit, which is zero for all blocks except for the last one.
writeNibble in class OutputBitStreamx - a natural number.IOExceptionpublic int writeLongNibble(long x)
throws IOException
OutputBitStreamwriteLongNibble in class OutputBitStreamx - a long natural number.IOExceptionOutputBitStream.writeNibble(int)Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.