Class BitBuffer

java.lang.Object
io.nayuki.qrcodegen.BitBuffer
All Implemented Interfaces:
java.lang.Cloneable

public final class BitBuffer
extends java.lang.Object
implements java.lang.Cloneable
An appendable sequence of bits (0s and 1s). Mainly used by QrSegment.
  • Constructor Summary

    Constructors
    Constructor Description
    BitBuffer()
    Constructs an empty bit buffer (length 0).
  • Method Summary

    Modifier and Type Method Description
    void appendBits​(int val, int len)
    Appends the specified number of low-order bits of the specified value to this buffer.
    void appendData​(BitBuffer bb)
    Appends the content of the specified bit buffer to this buffer.
    int bitLength()
    Returns the length of this sequence, which is a non-negative value.
    BitBuffer clone()
    Returns a new copy of this buffer.
    int getBit​(int index)
    Returns the bit at the specified index, yielding 0 or 1.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BitBuffer

      public BitBuffer()
      Constructs an empty bit buffer (length 0).
  • Method Details

    • bitLength

      public int bitLength()
      Returns the length of this sequence, which is a non-negative value.
      Returns:
      the length of this sequence
    • getBit

      public int getBit​(int index)
      Returns the bit at the specified index, yielding 0 or 1.
      Parameters:
      index - the index to get the bit at
      Returns:
      the bit at the specified index
      Throws:
      java.lang.IndexOutOfBoundsException - if index < 0 or index ≥ bitLength
    • appendBits

      public void appendBits​(int val, int len)
      Appends the specified number of low-order bits of the specified value to this buffer. Requires 0 ≤ len ≤ 31 and 0 ≤ val < 2len.
      Parameters:
      val - the value to append
      len - the number of low-order bits in the value to take
      Throws:
      java.lang.IllegalArgumentException - if the value or number of bits is out of range
      java.lang.IllegalStateException - if appending the data would make bitLength exceed Integer.MAX_VALUE
    • appendData

      public void appendData​(BitBuffer bb)
      Appends the content of the specified bit buffer to this buffer.
      Parameters:
      bb - the bit buffer whose data to append (not null)
      Throws:
      java.lang.NullPointerException - if the bit buffer is null
      java.lang.IllegalStateException - if appending the data would make bitLength exceed Integer.MAX_VALUE
    • clone

      public BitBuffer clone()
      Returns a new copy of this buffer.
      Overrides:
      clone in class java.lang.Object
      Returns:
      a new copy of this buffer (not null)