@Override public int read() throws IOException { checkClosed(); if (!buffer.hasRemaining()) { fillBuffer(); } if (!buffer.hasRemaining()) { return -1; } bitOffset = 0; streamPos++; return buffer.get() & 0xff; }
@Override public int readBit() throws IOException { checkClosed(); if (!buffer.hasRemaining()) { fillBuffer(); if (!buffer.hasRemaining()) { throw new EOFException(); } } // Compute final bit offset before we call read() and seek() int newBitOffset = (this.bitOffset + 1) & 0x7; int val = buffer.get() & 0xff; if (newBitOffset != 0) { // Move byte position back if in the middle of a byte buffer.position(buffer.position() - 1); // Shift the bit to be read to the rightmost position val >>= 8 - newBitOffset; } else { streamPos++; } this.bitOffset = newBitOffset; return val & 0x1; }
while (bitsToRead > 0) { if (!buffer.hasRemaining()) { fillBuffer();
@Override public int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { checkClosed(); bitOffset = 0; if (!buffer.hasRemaining()) { // Bypass buffer if buffer is empty for reads longer than buffer if (pLength >= buffer.capacity()) { return readDirect(pBuffer, pOffset, pLength); } else { fillBuffer(); } } return readBuffered(pBuffer, pOffset, pLength); }
@Override public int read() throws IOException { if (!buffer.hasRemaining()) { fillBuffer(); } if (!buffer.hasRemaining()) { return -1; } bitOffset = 0; streamPos++; return buffer.get() & 0xff; }
@Override public int read() throws IOException { if (!isBufferValid()) { fillBuffer(); } if (mBufferLength <= 0) { return -1; } bitOffset = 0; streamPos++; return mBuffer[mBufferPos++] & 0xff; }
@Override public int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { bitOffset = 0; if (!buffer.hasRemaining()) { // Bypass cache if cache is empty for reads longer than buffer if (pLength >= buffer.capacity()) { return readDirect(pBuffer, pOffset, pLength); } else { fillBuffer(); } } return readBuffered(pBuffer, pOffset, pLength); }
@Override public int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { bitOffset = 0; if (!isBufferValid()) { // Bypass cache if cache is empty for reads longer than buffer if (pLength >= mBuffer.length) { return readDirect(pBuffer, pOffset, pLength); } else { fillBuffer(); } } return readBuffered(pBuffer, pOffset, pLength); }