VorbisBitArray { public int readBits(int numBits) { int tempByteOffset = byteOffset; int bitsRead = Math.min(numBits, 8 - bitOffset); int returnValue = ((data[tempByteOffset++] & 0xFF) >> bitOffset) & (0xFF >> (8 - bitsRead)); while (bitsRead < numBits) { returnValue |= (data[tempByteOffset++] & 0xFF) << bitsRead; bitsRead += 8; } returnValue &= 0xFFFFFFFF >>> (32 - numBits); skipBits(numBits); return returnValue; } VorbisBitArray(byte[] data); void reset(); boolean readBit(); int readBits(int numBits); void skipBits(int numBits); int getPosition(); void setPosition(int position); int bitsLeft();  }
@Test public void testReadInt32() { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0xF0, 0x0F, 0xF0, 0x0F)); assertThat(bitArray.readBits(32)).isEqualTo(0x0FF00FF0); bitArray = new VorbisBitArray(TestUtil.createByteArray(0x0F, 0xF0, 0x0F, 0xF0)); assertThat(bitArray.readBits(32)).isEqualTo(0xF00FF00F); }
@Test public void testReadBits() throws Exception { VorbisBitArray bitArray = new VorbisBitArray(TestUtil.createByteArray(0x03, 0x22)); assertThat(bitArray.readBits(2)).isEqualTo(3); bitArray.skipBits(6); assertThat(bitArray.readBits(2)).isEqualTo(2); bitArray.skipBits(2); assertThat(bitArray.readBits(2)).isEqualTo(2); bitArray.reset(); assertThat(bitArray.readBits(16)).isEqualTo(0x2203); }