@Test
public void testWrite() throws Exception {

  final ByteArrayOutputStream buff = new ByteArrayOutputStream();
  final JBBPBitOutputStream out = new JBBPBitOutputStream(buff);
  for (int i = 0; i < 256; ) {
    out.write(i++);
    out.writeBits(i++, JBBPBitNumber.BITS_8);
  }
  assertEquals(256, out.getCounter());
  final byte[] written = buff.toByteArray();
  assertEquals(256, written.length);
  for (int i = 0; i < 256; i++) {
    assertEquals(i, written[i] & 0xFF, "Pos " + i);
  }
}