JBBPBitInputStream extends FilterInputStream implements JBBPCountableBitStream { @SuppressWarnings("NullableProblems") @Override public int read(final byte[] array, final int offset, final int length) throws IOException { if (this.bitsInBuffer == 0) { int readBytes = 0; int tmpoffset = offset; int tmplen = length; while (tmplen > 0) { int read = this.in.read(array, tmpoffset, tmplen); if (read < 0) { readBytes = readBytes == 0 ? read : readBytes; break; } tmplen -= read; tmpoffset += read; readBytes += read; this.byteCounter += read; } if (this.msb0) { int index = offset; int number = readBytes; while (number > 0) { array[index] = JBBPUtils.reverseBitsInByte(array[index]); index++; number--; } } return readBytes; } else { int count = length; int i = offset; while (count > 0) { final int nextByte = this.readBits(JBBPBitNumber.BITS_8); if (nextByte < 0) { break; } count--; array[i++] = (byte) nextByte; } return length - count; } } 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 testRead_WithoutOffset() throws Exception { final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(JBBPUtils.str2bin("01010111_01010111_01010111_00011000_01010101_01100011_00000001", JBBPBitOrder.MSB0))); assertEquals(0xEA, in.read()); assertEquals(0xEA, in.read()); assertEquals(0xEA, in.read()); assertEquals(0x18, in.read()); assertEquals(0xAA, in.read()); assertEquals(0xC6, in.read()); assertEquals(0x80, in.read()); assertEquals(-1, in.read()); }