assertEquals(2, bs.readBits(8, true).byteValue());
}
@Test
public void testWriteMarks() throws Exception {
BitStream bs = new BitStream(2);
bs.writeBits(BigInteger.ONE, 8);
bs.setWriteMark();
bs.writeBits(BigInteger.TEN, 8);
assertEquals(Byte.SIZE * 2, bs.available());
assertEquals(2, bs.bytes());
byte[] data = bs.toByteArray();
assertEquals(2, data.length);
assertEquals(1, data[0]);
assertEquals(10, data[1]);
bs.goToWriteMark();
bs.writeBits(BigInteger.ZERO, 8);
assertEquals(Byte.SIZE * 2, bs.available());
assertEquals(2, bs.bytes());
data = bs.toByteArray();
assertEquals(2, data.length);
assertEquals(1, data[0]);
assertEquals(0, data[1]);
bs.clearWriteMark();
bs.writeBits(BigInteger.TEN, 8);
data = bs.toByteArray();
assertEquals(3, data.length);
assertEquals(Byte.SIZE * 3, bs.available());
assertEquals(130, bs.bytes());
bs.goToWriteFromBeginning();
bs.writeBits(BigInteger.ZERO, 8);
bs.writeBits(BigInteger.ZERO, 8);
data = bs.toByteArray();
assertEquals(0, data[0]);
assertEquals(0, data[1]);
}