|
||||||||||
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
OutputBitStream
This 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 OutputBitStream
IOException
public void close() throws IOException
OutputBitStream
close
in class OutputBitStream
IOException
public long writtenBits()
OutputBitStream
writtenBits
in class OutputBitStream
public void writtenBits(long writtenBits)
OutputBitStream
This 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 OutputBitStream
IOException
public void position(long position) throws IOException
OutputBitStream
RepositionableStream
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 OutputBitStream
position
- the new position expressed as a bit offset; it must be byte-aligned.
IOException
FileChannel.position(long)
public int write(byte[] bits, int len) throws IOException
OutputBitStream
write
in class OutputBitStream
bits
- 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 OutputBitStream
bit
- a bit.
IOException
public int writeBit(int bit) throws IOException
OutputBitStream
writeBit
in class OutputBitStream
bit
- a bit.
IOException
public int writeInt(int x, int len) throws IOException
OutputBitStream
writeInt
in class OutputBitStream
x
- 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 OutputBitStream
x
- 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 OutputBitStream
x
- a natural number.
IOException
public long writeLongUnary(long x) throws IOException
OutputBitStream
writeLongUnary
in class OutputBitStream
x
- a long natural number.
IOException
OutputBitStream.writeUnary(int)
public int writeGamma(int x) throws IOException
OutputBitStream
writeGamma
in class OutputBitStream
x
- a natural number.
IOException
public int writeLongGamma(long x) throws IOException
OutputBitStream
writeLongGamma
in class OutputBitStream
x
- a long natural number.
IOException
OutputBitStream.writeGamma(int)
public int writeDelta(int x) throws IOException
OutputBitStream
writeDelta
in class OutputBitStream
x
- a natural number.
IOException
public int writeLongDelta(long x) throws IOException
OutputBitStream
writeLongDelta
in class OutputBitStream
x
- a long natural number.
IOException
OutputBitStream.writeDelta(int)
public int writeMinimalBinary(int x, int b) throws IOException
OutputBitStream
writeMinimalBinary
in class OutputBitStream
x
- a natural number.b
- a strict upper bound for x
.
IOException
public int writeMinimalBinary(int x, int b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeMinimalBinary(int,int)
because it does not
have to compute log2b
.
writeMinimalBinary
in class OutputBitStream
x
- 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 OutputBitStream
x
- a natural number.b
- a strict upper bound for x
.
IOException
public int writeLongMinimalBinary(long x, long b, int log2b) throws IOException
OutputBitStream
OutputBitStream.writeLongMinimalBinary(long,long)
because it does not
have to compute log2b
.
writeLongMinimalBinary
in class OutputBitStream
x
- 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
OutputBitStream
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 OutputBitStream
x
- a natural number.b
- the modulus for the coding.
IOException
public int writeGolomb(int x, int b, int log2b) throws IOException
OutputBitStream
OutputBitStream.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 OutputBitStream
x
- 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
OutputBitStream
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 OutputBitStream
x
- a long natural number.b
- the modulus for the coding.
IOException
public long writeLongGolomb(long x, long b, int log2b) throws IOException
OutputBitStream
OutputBitStream.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 OutputBitStream
x
- 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
OutputBitStream
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.
writeSkewedGolomb
in class OutputBitStream
x
- a natural number.b
- the modulus for the coding.
IOException
public long writeLongSkewedGolomb(long x, long b) throws IOException
OutputBitStream
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.
writeLongSkewedGolomb
in class OutputBitStream
x
- 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 OutputBitStream
x
- a natural number.k
- the shrinking factor.
IOException
public long writeLongZeta(long x, int k) throws IOException
OutputBitStream
writeLongZeta
in class OutputBitStream
x
- 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 |