|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectit.unimi.dsi.mg4j.io.OutputBitStream
it.unimi.dsi.mg4j.io.DebugOutputBitStream
A debugging wrapper for output bit streams.
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();
| Field Summary |
| Fields inherited from class it.unimi.dsi.mg4j.io.OutputBitStream |
DEFAULT_BUFFER_SIZE |
| Constructor Summary | |
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. |
|
| Method Summary | |
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. |
int |
write(byte[] bits,
int 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. |
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. |
long |
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 |
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. |
| Methods inherited from class it.unimi.dsi.mg4j.io.OutputBitStream |
writeDelta, writeLongNibble, writeNibble |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public 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.| Method Detail |
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 class OutputBitStreamIOException
public void close()
throws IOException
OutputBitStream
close in class OutputBitStreamIOExceptionpublic long writtenBits()
OutputBitStream
writtenBits 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 OutputBitStream
public int align()
throws IOException
OutputBitStream
align in class OutputBitStreamIOException
public 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 int write(byte[] bits,
int len)
throws IOException
OutputBitStream
write in class OutputBitStreambits - a vector containing the bits to be written.len - a bit length.
len).
IOException
public int writeBit(boolean bit)
throws IOException
OutputBitStream
writeBit in class OutputBitStreambit - a bit.
IOException
public int writeBit(int bit)
throws IOException
OutputBitStream
writeBit in class OutputBitStreambit - a bit.
IOException
public int writeInt(int x,
int len)
throws IOException
OutputBitStream
writeInt 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).
IOException
public int writeLong(long x,
int len)
throws IOException
OutputBitStream
writeLong 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).
IOException
public int writeUnary(int x)
throws IOException
OutputBitStream
writeUnary in class OutputBitStreamx - a natural number.
IOException
public long writeLongUnary(long x)
throws IOException
OutputBitStream
writeLongUnary in class OutputBitStreamx - a long natural number.
IOExceptionOutputBitStream.writeUnary(int)
public int writeGamma(int x)
throws IOException
OutputBitStream
writeGamma in class OutputBitStreamx - a natural number.
IOException
public int writeLongGamma(long x)
throws IOException
OutputBitStream
writeLongGamma in class OutputBitStreamx - a long natural number.
IOExceptionOutputBitStream.writeGamma(int)
public int writeDelta(int x)
throws IOException
OutputBitStream
writeDelta in class OutputBitStreamx - a natural number.
IOException
public int writeLongDelta(long x)
throws IOException
OutputBitStream
writeLongDelta in class OutputBitStreamx - a long natural number.
IOExceptionOutputBitStream.writeDelta(int)
public int writeMinimalBinary(int x,
int b)
throws IOException
OutputBitStream
writeMinimalBinary in class OutputBitStreamx - a natural number.b - a strict upper bound for x.
IOException
public 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.
IOException
public int writeLongMinimalBinary(long x,
long b)
throws IOException
OutputBitStream
writeLongMinimalBinary in class OutputBitStreamx - a natural number.b - a strict upper bound for x.
IOException
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.
IOException
public int writeGolomb(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.
writeGolomb in class OutputBitStreamx - a natural number.b - the modulus for the coding.
IOException
public int writeGolomb(int x,
int b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeGolomb(int,int) because it does not
have to compute log2b.
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.log2b - the floor of the base-2 logarithm of the coding modulus (it is irrelevant when b is zero).
IOException
public long writeLongGolomb(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.
writeLongGolomb in class OutputBitStreamx - a long natural number.b - the modulus for the coding.
IOException
public long writeLongGolomb(long x,
long b,
int log2b)
throws IOException
OutputBitStreamOutputBitStream.writeLongGolomb(long,long) because it does not
have to compute log2b.
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.
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).
IOException
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.
IOException
public 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.
IOException
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.
A detailed analysis of ζ codes is given in
Paolo Boldi and Sebastiano Vigna, The WebGraph Framework II: Codes for the World-Wide Web.
writeZeta in class OutputBitStreamx - a natural number.k - the shrinking factor.
IOException
public long writeLongZeta(long x,
int k)
throws IOException
OutputBitStream
writeLongZeta in class OutputBitStreamx - a long natural number.k - the shrinking factor.
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||