### Question:
BitOutputStream extends NonBlockingBitOutputStream { @Override public void flush () throws IOException { m_aLock.lockedThrowing (super::flush); } BitOutputStream(@Nonnull final OutputStream aOS, @Nonnull final ByteOrder aByteOrder); @Override void writeBit(final int aBit); @Override void flush(); @Override void close();  }### Answer:
@Test public void testWriteManyBigEndian () throws IOException { final Random aRandom = new Random (); for (int i = 0; i < 200; i += 3) { final byte [] buf = new byte [i * 100]; aRandom.nextBytes (buf); try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { try (final BitOutputStream aBOS = new BitOutputStream (aBAOS, ByteOrder.BIG_ENDIAN)) { for (final byte b : buf) aBOS.writeBits (b & 0xff, 8); aBOS.flush (); } final byte [] written = aBAOS.toByteArray (); try (final BitInputStream aBIS = new BitInputStream (new NonBlockingByteArrayInputStream (written), ByteOrder.BIG_ENDIAN)) { aBAOS.reset (); for (final byte element : written) { final int nRead = aBIS.readBits (8); assertEquals (element & 0xff, (Integer.reverse (nRead) >> 24) & 0xff); aBAOS.write (nRead); } } final byte [] read = aBAOS.toByteArray (); assertArrayEquals (buf, read); } } }