Class DebugInputBitStream
- All Implemented Interfaces:
BooleanIterator,Closeable,Flushable,AutoCloseable,Iterator<Boolean>
public class DebugInputBitStream extends InputBitStream
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
-
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
Constructors Constructor Description DebugInputBitStream(InputBitStream ibs)Creates 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 Type Method Description voidalign()Aligns the stream.longavailable()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.voidclose()Closes the bit stream.voidflush()Flushes the bit stream.voidposition(long position)Sets this stream bit position, if it is based on aRepositionableStreamor on aFileChannel.voidread(byte[] bits, int len)Reads a sequence of bits.intreadBit()Reads a bit.longreadBits()Returns the number of bits read from this bit stream.voidreadBits(long readBits)Sets the number of bits read from this bit stream.intreadDelta()Reads a natural number in δ coding.intreadGamma()Reads a natural number in γ coding.intreadGolomb(int b)Reads a natural number in Golomb coding.intreadGolomb(int b, int log2b)Reads a natural number in Golomb coding.intreadInt(int len)Reads a fixed number of bits into an integer.longreadLong(int len)Reads a fixed number of bits into a long.longreadLongDelta()Reads a long natural number in δ coding.longreadLongGamma()Reads a long natural number in γ coding.longreadLongGolomb(long b)Reads a long natural number in Golomb coding.longreadLongGolomb(long b, int log2b)Reads a long natural number in Golomb coding.longreadLongMinimalBinary(long b)Reads a long natural number in a limited range using a minimal binary coding.longreadLongMinimalBinary(long b, int log2b)Reads a long natural number in a limited range using a minimal binary coding.longreadLongNibble()Reads a long natural number in variable-length nibble coding.longreadLongSkewedGolomb(long b)Reads a long natural number in skewed Golomb coding.longreadLongUnary()Reads a long natural number in unary coding.longreadLongZeta(int k)Reads a long natural number in ζ coding.intreadMinimalBinary(int b)Reads a natural number in a limited range using a minimal binary coding.intreadMinimalBinary(int b, int log2b)Reads a natural number in a limited range using a minimal binary coding.intreadNibble()Reads a natural number in variable-length nibble coding.intreadSkewedGolomb(int b)Reads a natural number in skewed Golomb coding.intreadUnary()Reads a natural number in unary coding.intreadZeta(int k)Reads a natural number in ζ coding.voidreset()Repositions this bit stream to the position at the time theInputBitStream.mark(int)method was last called.intskip(int n)Deprecated.longskip(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, skipZetasMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:InputBitStreamAligns the stream. After a call to this function, the stream is byte aligned. Bits that have been read to align are discarded.- Overrides:
alignin classInputBitStream
-
available
Description copied from class:InputBitStreamReturns 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:
availablein classInputBitStream- Returns:
- the number of bits that can be read from this bit stream without blocking.
- Throws:
IOException
-
close
Description copied from class:InputBitStreamCloses the bit stream. All resources associated with the stream are released.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputBitStream- Throws:
IOException
-
flush
public void flush()Description copied from class:InputBitStreamFlushes 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:
flushin interfaceFlushable- Overrides:
flushin classInputBitStream
-
position
Description copied from class:InputBitStreamSets this stream bit position, if it is based on aRepositionableStreamor on aFileChannel.Given an underlying stream that implements
RepositionableStreamor that can provide aFileChannelvia 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:
positionin classInputBitStream- Parameters:
position- the new position expressed as a bit offset.- Throws:
IOException- See Also:
FileChannel.position(long)
-
read
Description copied from class:InputBitStreamReads 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:
readin 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:InputBitStreamReads a bit.- Overrides:
readBitin classInputBitStream- Returns:
- the next bit from the stream.
- Throws:
IOException
-
readBits
public long readBits()Description copied from class:InputBitStreamReturns the number of bits read from this bit stream.- Overrides:
readBitsin classInputBitStream- Returns:
- the number of bits read so far.
-
readBits
public void readBits(long readBits)Description copied from class:InputBitStreamSets 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:
readBitsin classInputBitStream- Parameters:
readBits- the new value for the number of bits read so far.
-
readDelta
Description copied from class:InputBitStreamReads a natural number in δ coding.- Overrides:
readDeltain classInputBitStream- Returns:
- the next δ-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeDelta(int),InputBitStream.skipDeltas(int)
-
readGamma
Description copied from class:InputBitStreamReads a natural number in γ coding.- Overrides:
readGammain classInputBitStream- Returns:
- the next γ-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeGamma(int),InputBitStream.skipGammas(int)
-
readGolomb
Description copied from class:InputBitStreamReads 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
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readGolombin 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:
OutputBitStream.writeGolomb(int, int)
-
readGolomb
Description copied from class:InputBitStreamReads a natural number in Golomb coding.This method implements also the case in which
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readGolombin classInputBitStream- Parameters:
b- the modulus for the coding.- Returns:
- the next Golomb-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeGolomb(int, int)
-
readInt
Description copied from class:InputBitStreamReads a fixed number of bits into an integer.- Overrides:
readIntin classInputBitStream- Parameters:
len- a bit length.- Returns:
- an integer whose lower
lenbits are taken from the stream; the rest is zeroed. - Throws:
IOException
-
readLong
Description copied from class:InputBitStreamReads a fixed number of bits into a long.- Overrides:
readLongin classInputBitStream- Parameters:
len- a bit length.- Returns:
- a long whose lower
lenbits are taken from the stream; the rest is zeroed. - Throws:
IOException
-
readLongDelta
Description copied from class:InputBitStreamReads a long natural number in δ coding.- Overrides:
readLongDeltain classInputBitStream- Returns:
- the next δ-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeDelta(int),InputBitStream.skipDeltas(int)
-
readLongGamma
Description copied from class:InputBitStreamReads a long natural number in γ coding.- Overrides:
readLongGammain classInputBitStream- Returns:
- the next γ-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeGamma(int),InputBitStream.skipGammas(int)
-
readLongGolomb
Description copied from class:InputBitStreamReads 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
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongGolombin 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:
OutputBitStream.writeGolomb(int, int)
-
readLongGolomb
Description copied from class:InputBitStreamReads a long natural number in Golomb coding.This method implements also the case in which
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongGolombin classInputBitStream- Parameters:
b- the modulus for the coding.- Returns:
- the next Golomb-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeGolomb(int, int)
-
readLongMinimalBinary
Description copied from class:InputBitStreamReads 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:
readLongMinimalBinaryin 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:
OutputBitStream.writeMinimalBinary(int, int)
-
readLongMinimalBinary
Description copied from class:InputBitStreamReads a long natural number in a limited range using a minimal binary coding.- Overrides:
readLongMinimalBinaryin classInputBitStream- Parameters:
b- a strict upper bound.- Returns:
- the next minimally binary encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeMinimalBinary(int, int)
-
readLongNibble
Description copied from class:InputBitStreamReads a long natural number in variable-length nibble coding.- Overrides:
readLongNibblein classInputBitStream- Returns:
- the next variable-length nibble-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeNibble(int)
-
readLongSkewedGolomb
Description copied from class:InputBitStreamReads a long natural number in skewed Golomb coding.This method implements also the case in which
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readLongSkewedGolombin classInputBitStream- Parameters:
b- the modulus for the coding.- Returns:
- the next skewed Golomb-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeSkewedGolomb(int, int)
-
readLongUnary
Description copied from class:InputBitStreamReads 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:
readLongUnaryin classInputBitStream- Returns:
- the next unary-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeUnary(int)
-
readLongZeta
Description copied from class:InputBitStreamReads a long natural number in ζ coding.- Overrides:
readLongZetain classInputBitStream- Parameters:
k- the shrinking factor.- Returns:
- the next ζ-encoded long natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeZeta(int, int)
-
readMinimalBinary
Description copied from class:InputBitStreamReads 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:
readMinimalBinaryin 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:
OutputBitStream.writeMinimalBinary(int, int)
-
readMinimalBinary
Description copied from class:InputBitStreamReads a natural number in a limited range using a minimal binary coding.- Overrides:
readMinimalBinaryin classInputBitStream- Parameters:
b- a strict upper bound.- Returns:
- the next minimally binary encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeMinimalBinary(int, int)
-
readNibble
Description copied from class:InputBitStreamReads a natural number in variable-length nibble coding.- Overrides:
readNibblein classInputBitStream- Returns:
- the next variable-length nibble-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeNibble(int)
-
readSkewedGolomb
Description copied from class:InputBitStreamReads a natural number in skewed Golomb coding.This method implements also the case in which
bis 0: in this case, nothing will be read, and 0 will be returned.- Overrides:
readSkewedGolombin classInputBitStream- Parameters:
b- the modulus for the coding.- Returns:
- the next skewed Golomb-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeSkewedGolomb(int, int)
-
readUnary
Description copied from class:InputBitStreamReads a natural number in unary coding.- Overrides:
readUnaryin classInputBitStream- Returns:
- the next unary-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeUnary(int)
-
readZeta
Description copied from class:InputBitStreamReads a natural number in ζ coding.- Overrides:
readZetain classInputBitStream- Parameters:
k- the shrinking factor.- Returns:
- the next ζ-encoded natural number.
- Throws:
IOException- See Also:
OutputBitStream.writeZeta(int, int)
-
reset
Description copied from class:InputBitStreamRepositions this bit stream to the position at the time theInputBitStream.mark(int)method was last called.This method will just
flush the streamand delegate the reset to the underlyingInputStream.- Overrides:
resetin classInputBitStream- Throws:
IOException
-
skip
Deprecated.Description copied from class:InputBitStreamSkips over the given number of bits.- Specified by:
skipin interfaceBooleanIterator- Overrides:
skipin classInputBitStream- Parameters:
n- the number of bits to skip.- Returns:
- the number of bits actually skipped.
-
skip
Description copied from class:InputBitStreamSkips the given number of bits.- Overrides:
skipin classInputBitStream- Parameters:
n- the number of bits to skip.- Returns:
- the actual number of skipped bits.
- Throws:
IOException
-