/** * Reads a bit from the stream. Returns a boolean (true for 1; false for 0) if a bit is available, * or throws an EOFException if the end of stream is reached. * * @return the bit that was read (true = 1; false = 0) * @throws IOException if the stream is closed or another I/O error occurs * @throws EOFException when the next bit cannot be read because the end of stream is reached */ protected boolean doReadBit() throws IOException, EOFException { if (currentIndex >= bitArray .length()) // also reads a new byte from underlying stream if needed! (will also check // for closedness) throw new EOFException("End of stream reached"); return bitArray.get(currentIndex++); }
/** * The (estimated) number of bits left available for reading. Calls atEnd(). * * @return */ public int bitsAvailable() throws IOException { return bitArray.length() - currentIndex; }