Class BitStream

java.lang.Object
bdsup2sub.tools.BitStream

public class BitStream extends Object
Simple helper class to read bitwise from a buffer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Current byte from the buffer
    private int
    Bits left in current byte b
    private final byte[]
    Data buffer
    private int
    Offset to current byte in buffer
  • Constructor Summary

    Constructors
    Constructor
    Description
    BitStream(byte[] buffer)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
    readBits(int n)
    Read n bits from buffer (n <= 32)
    void
    Synchronize to next byte in data buffer (skip remaining 0-7 bits)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • buffer

      private final byte[] buffer
      Data buffer
    • byteOfs

      private int byteOfs
      Offset to current byte in buffer
    • b

      private int b
      Current byte from the buffer
    • bits

      private int bits
      Bits left in current byte b
  • Constructor Details

    • BitStream

      public BitStream(byte[] buffer)
      Parameters:
      buffer - Byte array to create bitstream for
  • Method Details

    • bitsLeft

      public int bitsLeft()
      Returns:
      Number of bits left in buffer
    • readBits

      public int readBits(int n)
      Read n bits from buffer (n <= 32)
      Parameters:
      n - Number of bits to read from buffer (n<=32)
      Returns:
      Value containing the n bits (last bit read is LSB)
    • syncToByte

      public void syncToByte()
      Synchronize to next byte in data buffer (skip remaining 0-7 bits)