JBBPBitInputStream extends FilterInputStream implements JBBPCountableBitStream { public void alignByte() { if (this.bitsInBuffer > 0 && this.bitsInBuffer < 8) { this.byteCounter++; this.bitsInBuffer = 0; } } JBBPBitInputStream(final InputStream in);  JBBPBitInputStream(final InputStream in, final JBBPBitOrder order); boolean[] readBoolArray(final int items); byte[] readBitsArray(final int items, final JBBPBitNumber bitNumber); byte[] readByteArray(final int items); byte[] readByteArray(final int items, final JBBPByteOrder byteOrder); short[] readShortArray(final int items, final JBBPByteOrder byteOrder); char[] readUShortArray(final int items, final JBBPByteOrder byteOrder); int[] readIntArray(final int items, final JBBPByteOrder byteOrder); float[] readFloatArray(final int items, final JBBPByteOrder byteOrder); long[] readLongArray(final int items, final JBBPByteOrder byteOrder); double[] readDoubleArray(final int items, final JBBPByteOrder byteOrder); int readUnsignedShort(final JBBPByteOrder byteOrder); int readInt(final JBBPByteOrder byteOrder); float readFloat(final JBBPByteOrder byteOrder); long readLong(final JBBPByteOrder byteOrder); double readDouble(final JBBPByteOrder byteOrder); @Override long getCounter(); @Override int getBitBuffer(); @Override int getBufferedBitsNumber(); @Override JBBPBitOrder getBitOrder(); byte readBitField(final JBBPBitNumber numOfBitsToRead); int readBits(final JBBPBitNumber numOfBitsToRead); boolean readBoolean(); int readByte(); @Override synchronized void reset(); @Override synchronized void mark(final int readlimit); void align(final long alignByteNumber); @Override long skip(final long numOfBytes); void alignByte(); boolean hasAvailableData(); @SuppressWarnings("NullableProblems") @Override int read(final byte[] array, final int offset, final int length); @Override void resetCounter(); @SuppressWarnings("NullableProblems") @Override int read(final byte[] array); @Override int read(); String readString(final JBBPByteOrder byteOrder); String[] readStringArray(final int items, final JBBPByteOrder byteOrder);  }
@Test public void testAlignByte() throws Exception { final byte[] testarray = JBBPUtils.str2bin("01111001 10111000"); final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(testarray)); in.alignByte(); assertEquals(0, in.getCounter()); assertEquals(0x19, in.readBits(JBBPBitNumber.BITS_5)); assertEquals(0, in.getCounter()); in.alignByte(); assertEquals(1, in.getCounter()); assertEquals(0x8, in.readBits(JBBPBitNumber.BITS_4)); assertEquals(1, in.getCounter()); assertEquals(0xB, in.readBits(JBBPBitNumber.BITS_4)); assertEquals(2, in.getCounter()); assertEquals(-1, in.read()); assertEquals(2, in.getCounter()); }