Class DebugInputBitStream

  • All Implemented Interfaces:
    it.unimi.dsi.fastutil.booleans.BooleanIterator, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, java.util.Iterator<java.lang.Boolean>, java.util.PrimitiveIterator<java.lang.Boolean,​it.unimi.dsi.fastutil.booleans.BooleanConsumer>

    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
    • Constructor Detail

      • DebugInputBitStream

        public DebugInputBitStream​(InputBitStream ibs,
                                   java.io.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 java.io.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:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: InputBitStream
        Closes the bit stream. All resources associated with the stream are released.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class InputBitStream
        Throws:
        java.io.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 java.io.Flushable
        Overrides:
        flush in class InputBitStream
      • position

        public void position​(long position)
                      throws java.io.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:
        java.io.IOException
        See Also:
        FileChannel.position(long)
      • read

        public void read​(byte[] bits,
                         int len)
                  throws java.io.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:
        java.io.IOException
      • readBit

        public int readBit()
                    throws java.io.IOException
        Description copied from class: InputBitStream
        Reads a bit.
        Overrides:
        readBit in class InputBitStream
        Returns:
        the next bit from the stream.
        Throws:
        java.io.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.
      • readGolomb

        public int readGolomb​(int b,
                              int log2b)
                       throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeGolomb(int, int)
      • readGolomb

        public int readGolomb​(int b)
                       throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeGolomb(int, int)
      • readInt

        public int readInt​(int len)
                    throws java.io.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:
        java.io.IOException
      • readLong

        public long readLong​(int len)
                      throws java.io.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:
        java.io.IOException
      • readLongGolomb

        public long readLongGolomb​(long b,
                                   int log2b)
                            throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeGolomb(int, int)
      • readLongGolomb

        public long readLongGolomb​(long b)
                            throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeGolomb(int, int)
      • readLongMinimalBinary

        public long readLongMinimalBinary​(long b)
                                   throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeMinimalBinary(int, int)
      • readLongNibble

        public long readLongNibble()
                            throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeNibble(int)
      • readLongSkewedGolomb

        public long readLongSkewedGolomb​(long b)
                                  throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeSkewedGolomb(int, int)
      • readLongUnary

        public long readLongUnary()
                           throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeUnary(int)
      • readLongZeta

        public long readLongZeta​(int k)
                          throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeZeta(int, int)
      • readNibble

        public int readNibble()
                       throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeNibble(int)
      • readSkewedGolomb

        public int readSkewedGolomb​(int b)
                             throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeSkewedGolomb(int, int)
      • readZeta

        public int readZeta​(int k)
                     throws java.io.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:
        java.io.IOException
        See Also:
        OutputBitStream.writeZeta(int, int)
      • reset

        public void reset()
                   throws java.io.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:
        java.io.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 it.unimi.dsi.fastutil.booleans.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 java.io.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:
        java.io.IOException