it.unimi.dsi.io
Class DebugInputBitStream

java.lang.Object
  extended by it.unimi.dsi.fastutil.booleans.AbstractBooleanIterator
      extended by it.unimi.dsi.io.InputBitStream
          extended by it.unimi.dsi.io.DebugInputBitStream
All Implemented Interfaces:
BooleanIterator, Closeable, Flushable, Iterator<Boolean>

public class DebugInputBitStream
extends InputBitStream

A debugging wrapper for input bit streams.

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:

!
reset();
+>
skip().

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
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
 void align()
          Aligns the stream.
 long available()
          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 a RepositionableStream or on a FileChannel.
 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 readDelta()
          Reads a natural number in δ coding.
 int readGamma()
          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 readLongDelta()
          Reads a long natural number in δ coding.
 long readLongGamma()
          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 readLongNibble()
          Reads a long natural number in variable-length nibble coding.
 long readLongSkewedGolomb(long b)
          Reads a long natural number in skewed Golomb coding.
 long readLongUnary()
          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 readNibble()
          Reads a natural number in variable-length nibble coding.
 int readSkewedGolomb(int b)
          Reads a natural number in skewed Golomb coding.
 int readUnary()
          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 the InputBitStream.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
hasNext, mark, markSupported, nextBoolean, readDeltas, readGammas, readLongShiftedGamma, readShiftedGamma, readShiftedGammas, readZetas, skipDeltas, skipDeltas, skipGammas, skipGammas, skipShiftedGammas, skipShiftedGammas, skipZetas, skipZetas
 
Methods inherited from class it.unimi.dsi.fastutil.booleans.AbstractBooleanIterator
next, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DebugInputBitStream

public DebugInputBitStream(InputBitStream ibs,
                           PrintStream pw)
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

public DebugInputBitStream(InputBitStream ibs)
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 Detail

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 class InputBitStream

available

public long available()
               throws IOException
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 class InputBitStream
Returns:
the number of bits that can be read from this bit stream without blocking.
Throws:
IOException

close

public void close()
           throws IOException
Description copied from class: InputBitStream
Closes the bit stream. All resources associated with the stream are released.

Specified by:
close in interface Closeable
Overrides:
close in class InputBitStream
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 interface Flushable
Overrides:
flush in class InputBitStream

position

public void position(long position)
              throws IOException
Description copied from class: InputBitStream
Sets this stream bit position, if it is based on a 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 InputBitStream.flush(), followed by a call to position(position / 8) on the byte stream, followed by a skip(position % 8).

Note that this method does not change the value returned by InputBitStream.readBits().

Overrides:
position in class InputBitStream
Parameters:
position - the new position expressed as a bit offset.
Throws:
IOException
See Also:
FileChannel.position(long)

read

public void read(byte[] bits,
                 int len)
          throws IOException
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 class InputBitStream
Parameters:
bits - an array of bytes to store the result.
len - the number of bits to read.
Throws:
IOException

readBit

public int readBit()
            throws IOException
Description copied from class: InputBitStream
Reads a bit.

Overrides:
readBit in class InputBitStream
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 class InputBitStream
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 a InputBitStream.flush().

Overrides:
readBits in class InputBitStream
Parameters:
readBits - the new value for the number of bits read so far.

readDelta

public int readDelta()
              throws IOException
Description copied from class: InputBitStream
Reads a natural number in δ coding.

Overrides:
readDelta in class InputBitStream
Returns:
the next δ-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeDelta(int), InputBitStream.skipDeltas(int)

readGamma

public int readGamma()
              throws IOException
Description copied from class: InputBitStream
Reads a natural number in γ coding.

Overrides:
readGamma in class InputBitStream
Returns:
the next γ-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeGamma(int), InputBitStream.skipGammas(int)

readGolomb

public int readGolomb(int b,
                      int log2b)
               throws IOException
Description copied from class: InputBitStream
Reads a natural number in Golomb coding. This method is faster than InputBitStream.readGolomb(int) because it does not have to compute log2b.

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 class InputBitStream
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

public int readGolomb(int b)
               throws IOException
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 class InputBitStream
Parameters:
b - the modulus for the coding.
Returns:
the next Golomb-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeGolomb(int, int)

readInt

public int readInt(int len)
            throws IOException
Description copied from class: InputBitStream
Reads a fixed number of bits into an integer.

Overrides:
readInt in class InputBitStream
Parameters:
len - a bit length.
Returns:
an integer whose lower len bits are taken from the stream; the rest is zeroed.
Throws:
IOException

readLong

public long readLong(int len)
              throws IOException
Description copied from class: InputBitStream
Reads a fixed number of bits into a long.

Overrides:
readLong in class InputBitStream
Parameters:
len - a bit length.
Returns:
a long whose lower len bits are taken from the stream; the rest is zeroed.
Throws:
IOException

readLongDelta

public long readLongDelta()
                   throws IOException
Description copied from class: InputBitStream
Reads a long natural number in δ coding.

Overrides:
readLongDelta in class InputBitStream
Returns:
the next δ-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeDelta(int), InputBitStream.skipDeltas(int)

readLongGamma

public long readLongGamma()
                   throws IOException
Description copied from class: InputBitStream
Reads a long natural number in γ coding.

Overrides:
readLongGamma in class InputBitStream
Returns:
the next γ-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeGamma(int), InputBitStream.skipGammas(int)

readLongGolomb

public long readLongGolomb(long b,
                           int log2b)
                    throws IOException
Description copied from class: InputBitStream
Reads a long natural number in Golomb coding. This method is faster than InputBitStream.readLongGolomb(long) because it does not have to compute log2b.

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 class InputBitStream
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

public long readLongGolomb(long b)
                    throws IOException
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 class InputBitStream
Parameters:
b - the modulus for the coding.
Returns:
the next Golomb-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeGolomb(int, int)

readLongMinimalBinary

public long readLongMinimalBinary(long b,
                                  int log2b)
                           throws IOException
Description copied from class: InputBitStream
Reads a long natural number in a limited range using a minimal binary coding. This method is faster than InputBitStream.readLongMinimalBinary(long) because it does not have to compute log2b.

Overrides:
readLongMinimalBinary in class InputBitStream
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

public long readLongMinimalBinary(long b)
                           throws IOException
Description copied from class: InputBitStream
Reads a long natural number in a limited range using a minimal binary coding.

Overrides:
readLongMinimalBinary in class InputBitStream
Parameters:
b - a strict upper bound.
Returns:
the next minimally binary encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeMinimalBinary(int, int)

readLongNibble

public long readLongNibble()
                    throws IOException
Description copied from class: InputBitStream
Reads a long natural number in variable-length nibble coding.

Overrides:
readLongNibble in class InputBitStream
Returns:
the next variable-length nibble-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeNibble(int)

readLongSkewedGolomb

public long readLongSkewedGolomb(long b)
                          throws IOException
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 class InputBitStream
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

public long readLongUnary()
                   throws IOException
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 class InputBitStream
Returns:
the next unary-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeUnary(int)

readLongZeta

public long readLongZeta(int k)
                  throws IOException
Description copied from class: InputBitStream
Reads a long natural number in ζ coding.

Overrides:
readLongZeta in class InputBitStream
Parameters:
k - the shrinking factor.
Returns:
the next ζ-encoded long natural number.
Throws:
IOException
See Also:
OutputBitStream.writeZeta(int, int)

readMinimalBinary

public int readMinimalBinary(int b,
                             int log2b)
                      throws IOException
Description copied from class: InputBitStream
Reads a natural number in a limited range using a minimal binary coding. This method is faster than InputBitStream.readMinimalBinary(int) because it does not have to compute log2b.

Overrides:
readMinimalBinary in class InputBitStream
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

public int readMinimalBinary(int b)
                      throws IOException
Description copied from class: InputBitStream
Reads a natural number in a limited range using a minimal binary coding.

Overrides:
readMinimalBinary in class InputBitStream
Parameters:
b - a strict upper bound.
Returns:
the next minimally binary encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeMinimalBinary(int, int)

readNibble

public int readNibble()
               throws IOException
Description copied from class: InputBitStream
Reads a natural number in variable-length nibble coding.

Overrides:
readNibble in class InputBitStream
Returns:
the next variable-length nibble-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeNibble(int)

readSkewedGolomb

public int readSkewedGolomb(int b)
                     throws IOException
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 class InputBitStream
Parameters:
b - the modulus for the coding.
Returns:
the next skewed Golomb-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeSkewedGolomb(int, int)

readUnary

public int readUnary()
              throws IOException
Description copied from class: InputBitStream
Reads a natural number in unary coding.

Overrides:
readUnary in class InputBitStream
Returns:
the next unary-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeUnary(int)

readZeta

public int readZeta(int k)
             throws IOException
Description copied from class: InputBitStream
Reads a natural number in ζ coding.

Overrides:
readZeta in class InputBitStream
Parameters:
k - the shrinking factor.
Returns:
the next ζ-encoded natural number.
Throws:
IOException
See Also:
OutputBitStream.writeZeta(int, int)

reset

public void reset()
           throws IOException
Description copied from class: InputBitStream
Repositions this bit stream to the position at the time the InputBitStream.mark(int) method was last called.

This method will just flush the stream and delegate the reset to the underlying InputStream.

Overrides:
reset in class InputBitStream
Throws:
IOException

skip

@Deprecated
public int skip(int n)
Deprecated. 

Description copied from class: InputBitStream
Skips over the given number of bits.

Specified by:
skip in interface BooleanIterator
Overrides:
skip in class InputBitStream
Parameters:
n - the number of bits to skip.
Returns:
the number of bits actually skipped.

skip

public long skip(long n)
          throws IOException
Description copied from class: InputBitStream
Skips the given number of bits.

Overrides:
skip in class InputBitStream
Parameters:
n - the number of bits to skip.
Returns:
the actual number of skipped bits.
Throws:
IOException