Class DebugInputBitStream
- All Implemented Interfaces:
BooleanIterator
,Closeable
,Flushable
,AutoCloseable
,Iterator<Boolean>
,PrimitiveIterator<Boolean,
BooleanConsumer>
This class can be used to wrap an input bit stream. The semantics of the
resulting read operations is unchanged, but each operation will be logged. The
conventions are the same as those of DebugOutputBitStream
,
with the following additions:
- Since:
- 1.1
- Author:
- Sebastiano Vigna
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.PrimitiveIterator
PrimitiveIterator.OfDouble, PrimitiveIterator.OfInt, PrimitiveIterator.OfLong
-
Field Summary
Fields inherited from class it.unimi.dsi.io.InputBitStream
avail, buffer, DEFAULT_BUFFER_SIZE, DELTA, fileChannel, fill, GAMMA, is, pos, position, repositionableStream, SHIFTED_GAMMA, wrapping, ZETA_3
-
Constructor Summary
ConstructorDescriptionCreates a new debug input bit stream wrapping a given input bit stream and logging on standard error.DebugInputBitStream
(InputBitStream ibs, PrintStream pw) Creates a new debug input bit stream wrapping a given input bit stream and logging on a given writer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
align()
Aligns the stream.long
Returns the number of bits that can be read (or skipped over) from this bit stream without blocking by the next caller of a method.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 aRepositionableStream
or on aFileChannel
.void
read
(byte[] bits, int len) Reads a sequence of bits.int
readBit()
Reads a bit.long
readBits()
Returns the number of bits read from this bit stream.void
readBits
(long readBits) Sets the number of bits read from this bit stream.int
Reads a natural number in δ coding.int
Reads a natural number in γ coding.int
readGolomb
(int b) Reads a natural number in Golomb coding.int
readGolomb
(int b, int log2b) Reads a natural number in Golomb coding.int
readInt
(int len) Reads a fixed number of bits into an integer.long
readLong
(int len) Reads a fixed number of bits into a long.long
Reads a long natural number in δ coding.long
Reads a long natural number in γ coding.long
readLongGolomb
(long b) Reads a long natural number in Golomb coding.long
readLongGolomb
(long b, int log2b) Reads a long natural number in Golomb coding.long
readLongMinimalBinary
(long b) Reads a long natural number in a limited range using a minimal binary coding.long
readLongMinimalBinary
(long b, int log2b) Reads a long natural number in a limited range using a minimal binary coding.long
Reads a long natural number in variable-length nibble coding.long
readLongSkewedGolomb
(long b) Reads a long natural number in skewed Golomb coding.long
Reads a long natural number in unary coding.long
readLongZeta
(int k) Reads a long natural number in ζ coding.int
readMinimalBinary
(int b) Reads a natural number in a limited range using a minimal binary coding.int
readMinimalBinary
(int b, int log2b) Reads a natural number in a limited range using a minimal binary coding.int
Reads a natural number in variable-length nibble coding.int
readSkewedGolomb
(int b) Reads a natural number in skewed Golomb coding.int
Reads a natural number in unary coding.int
readZeta
(int k) Reads a natural number in ζ coding.void
reset()
Repositions this bit stream to the position at the time theInputBitStream.mark(int)
method was last called.int
skip
(int n) Deprecated.long
skip
(long n) Skips the given number of bits.Methods inherited from class it.unimi.dsi.io.InputBitStream
checkLength, copyTo, hasNext, mark, markSupported, nextBoolean, position, readDeltas, readGammas, readLongShiftedGamma, readShiftedGamma, readShiftedGammas, readZetas, skipDeltas, skipDeltas, skipGammas, skipGammas, skipShiftedGammas, skipShiftedGammas, skipZetas, skipZetas
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface it.unimi.dsi.fastutil.booleans.BooleanIterator
forEachRemaining, forEachRemaining, next
-
Constructor Details
-
DebugInputBitStream
Creates a new debug input bit stream wrapping a given input bit stream and logging on a given writer.- Parameters:
ibs
- the input bit stream to wrap.pw
- a print stream that will receive the logging data.
-
DebugInputBitStream
Creates a new debug input bit stream wrapping a given input bit stream and logging on standard error.- Parameters:
ibs
- the input bit stream to wrap.
-
-
Method Details
-
align
public void align()Description copied from class:InputBitStream
Aligns the stream. After a call to this function, the stream is byte aligned. Bits that have been read to align are discarded.- Overrides:
align
in classInputBitStream
-
available
Description copied from class:InputBitStream
Returns the number of bits that can be read (or skipped over) from this bit stream without blocking by the next caller of a method.- Overrides:
available
in classInputBitStream
- Returns:
- the number of bits that can be read from this bit stream without blocking.
- Throws:
IOException
-
close
Description copied from class:InputBitStream
Closes the bit stream. All resources associated with the stream are released.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputBitStream
- Throws:
IOException
-
flush
public void flush()Description copied from class:InputBitStream
Flushes the bit stream. All state information associated with the stream is reset. This includes bytes prefetched from the stream, bits in the bit buffer and unget'd bits.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 read will draw data from the stream.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classInputBitStream
-
position
Description copied from class:InputBitStream
Sets this stream bit position, if it is based on aRepositionableStream
or on aFileChannel
.Given an underlying stream that implements
RepositionableStream
or that can provide aFileChannel
via thegetChannel()
method, a call to this method has the same semantics of aInputBitStream.flush()
, followed by a call toposition(position / 8)
on the byte stream, followed by askip(position % 8)
.Note that this method does not change the value returned by
InputBitStream.readBits()
.- Overrides:
position
in classInputBitStream
- Parameters:
position
- the new position expressed as a bit offset.- Throws:
IOException
- See Also:
-
read
Description copied from class:InputBitStream
Reads a sequence of bits. Bits will be read in the natural way: the first bit is bit 7 of the first byte, the eightth bit is bit 0 of the first byte, the ninth bit is bit 7 of the second byte and so on.- Overrides:
read
in classInputBitStream
- Parameters:
bits
- an array of bytes to store the result.len
- the number of bits to read.- Throws:
IOException
-
readBit
Description copied from class:InputBitStream
Reads a bit.- Overrides:
readBit
in classInputBitStream
- Returns:
- the next bit from the stream.
- Throws:
IOException
-
readBits
public long readBits()Description copied from class:InputBitStream
Returns the number of bits read from this bit stream.- Overrides:
readBits
in classInputBitStream
- Returns:
- the number of bits read so far.
-
readBits
public void readBits(long readBits) Description copied from class:InputBitStream
Sets the number of bits read from this bit stream.This method is provided so that, for instance, the user can reset via
readBits(0)
the read-bits count after aInputBitStream.flush()
.- Overrides:
readBits
in classInputBitStream
- Parameters:
readBits
- the new value for the number of bits read so far.
-
readDelta
Description copied from class:InputBitStream
Reads a natural number in δ coding.- Overrides:
readDelta
in classInputBitStream
- Returns:
- the next δ-encoded natural number.
- Throws:
IOException
- See Also:
-
readGamma
Description copied from class:InputBitStream
Reads a natural number in γ coding.- Overrides:
readGamma
in classInputBitStream
- Returns:
- the next γ-encoded natural number.
- Throws:
IOException
- See Also:
-
readGolomb
Description copied from class:InputBitStream
Reads a natural number in Golomb coding. This method is faster thanInputBitStream.readGolomb(int)
because it does not have to computelog2b
.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.log2b
- the floor of the base-2 logarithm of the coding modulus.- Returns:
- the next Golomb-encoded natural number.
- Throws:
IOException
- See Also:
-
readGolomb
Description copied from class:InputBitStream
Reads a natural number in Golomb coding.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.- Returns:
- the next Golomb-encoded natural number.
- Throws:
IOException
- See Also:
-
readInt
Description copied from class:InputBitStream
Reads a fixed number of bits into an integer.- Overrides:
readInt
in classInputBitStream
- Parameters:
len
- a bit length.- Returns:
- an integer whose lower
len
bits are taken from the stream; the rest is zeroed. - Throws:
IOException
-
readLong
Description copied from class:InputBitStream
Reads a fixed number of bits into a long.- Overrides:
readLong
in classInputBitStream
- Parameters:
len
- a bit length.- Returns:
- a long whose lower
len
bits are taken from the stream; the rest is zeroed. - Throws:
IOException
-
readLongDelta
Description copied from class:InputBitStream
Reads a long natural number in δ coding.- Overrides:
readLongDelta
in classInputBitStream
- Returns:
- the next δ-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongGamma
Description copied from class:InputBitStream
Reads a long natural number in γ coding.- Overrides:
readLongGamma
in classInputBitStream
- Returns:
- the next γ-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongGolomb
Description copied from class:InputBitStream
Reads a long natural number in Golomb coding. This method is faster thanInputBitStream.readLongGolomb(long)
because it does not have to computelog2b
.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.log2b
- the floor of the base-2 logarithm of the coding modulus.- Returns:
- the next Golomb-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongGolomb
Description copied from class:InputBitStream
Reads a long natural number in Golomb coding.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.- Returns:
- the next Golomb-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongMinimalBinary
Description copied from class:InputBitStream
Reads a long natural number in a limited range using a minimal binary coding. This method is faster thanInputBitStream.readLongMinimalBinary(long)
because it does not have to computelog2b
.- Overrides:
readLongMinimalBinary
in classInputBitStream
- Parameters:
b
- a strict upper bound.log2b
- the floor of the base-2 logarithm of the bound.- Returns:
- the next minimally binary encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongMinimalBinary
Description copied from class:InputBitStream
Reads a long natural number in a limited range using a minimal binary coding.- Overrides:
readLongMinimalBinary
in classInputBitStream
- Parameters:
b
- a strict upper bound.- Returns:
- the next minimally binary encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongNibble
Description copied from class:InputBitStream
Reads a long natural number in variable-length nibble coding.- Overrides:
readLongNibble
in classInputBitStream
- Returns:
- the next variable-length nibble-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongSkewedGolomb
Description copied from class:InputBitStream
Reads a long natural number in skewed Golomb coding.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongSkewedGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.- Returns:
- the next skewed Golomb-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongUnary
Description copied from class:InputBitStream
Reads a long natural number in unary coding. Note that by unary coding we mean that 1 encodes 0, 01 encodes 1 and so on.- Overrides:
readLongUnary
in classInputBitStream
- Returns:
- the next unary-encoded long natural number.
- Throws:
IOException
- See Also:
-
readLongZeta
Description copied from class:InputBitStream
Reads a long natural number in ζ coding.- Overrides:
readLongZeta
in classInputBitStream
- Parameters:
k
- the shrinking factor.- Returns:
- the next ζ-encoded long natural number.
- Throws:
IOException
- See Also:
-
readMinimalBinary
Description copied from class:InputBitStream
Reads a natural number in a limited range using a minimal binary coding. This method is faster thanInputBitStream.readMinimalBinary(int)
because it does not have to computelog2b
.- Overrides:
readMinimalBinary
in classInputBitStream
- Parameters:
b
- a strict upper bound.log2b
- the floor of the base-2 logarithm of the bound.- Returns:
- the next minimally binary encoded natural number.
- Throws:
IOException
- See Also:
-
readMinimalBinary
Description copied from class:InputBitStream
Reads a natural number in a limited range using a minimal binary coding.- Overrides:
readMinimalBinary
in classInputBitStream
- Parameters:
b
- a strict upper bound.- Returns:
- the next minimally binary encoded natural number.
- Throws:
IOException
- See Also:
-
readNibble
Description copied from class:InputBitStream
Reads a natural number in variable-length nibble coding.- Overrides:
readNibble
in classInputBitStream
- Returns:
- the next variable-length nibble-encoded natural number.
- Throws:
IOException
- See Also:
-
readSkewedGolomb
Description copied from class:InputBitStream
Reads a natural number in skewed Golomb coding.This method implements also the case in which
b
is 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readSkewedGolomb
in classInputBitStream
- Parameters:
b
- the modulus for the coding.- Returns:
- the next skewed Golomb-encoded natural number.
- Throws:
IOException
- See Also:
-
readUnary
Description copied from class:InputBitStream
Reads a natural number in unary coding.- Overrides:
readUnary
in classInputBitStream
- Returns:
- the next unary-encoded natural number.
- Throws:
IOException
- See Also:
-
readZeta
Description copied from class:InputBitStream
Reads a natural number in ζ coding.- Overrides:
readZeta
in classInputBitStream
- Parameters:
k
- the shrinking factor.- Returns:
- the next ζ-encoded natural number.
- Throws:
IOException
- See Also:
-
reset
Description copied from class:InputBitStream
Repositions this bit stream to the position at the time theInputBitStream.mark(int)
method was last called.This method will just
flush the stream
and delegate the reset to the underlyingInputStream
.- Overrides:
reset
in classInputBitStream
- Throws:
IOException
-
skip
Deprecated.Description copied from class:InputBitStream
Skips over the given number of bits.- Specified by:
skip
in interfaceBooleanIterator
- Overrides:
skip
in classInputBitStream
- Parameters:
n
- the number of bits to skip.- Returns:
- the number of bits actually skipped.
-
skip
Description copied from class:InputBitStream
Skips the given number of bits.- Overrides:
skip
in classInputBitStream
- Parameters:
n
- the number of bits to skip.- Returns:
- the actual number of skipped bits.
- Throws:
IOException
-