private int readAhead(final byte[] pBytes, final int pOffset, final int pLength) throws IOException { int length; length = stream.read(pBytes, pOffset, pLength); if (length > 0) { streamPosition += length; getCache().write(pBytes, pOffset, length); } return length; }
@Override public int read(byte[] pBytes, int pOffset, int pLength) throws IOException { checkOpen(); int length; if (position == streamPosition) { // Read bytes from the stream length = readAhead(pBytes, pOffset, pLength); //System.out.println("Read " + length + " byte from stream"); } else { // ...or read bytes from the cache syncPosition(); length = getCache().read(pBytes, pOffset, (int) Math.min(pLength, streamPosition - position)); //System.out.println("Read " + length + " byte from cache"); } // TODO: This field is not REALLY considered accessible.. :-P if (length > 0) { position += length; } return length; }
@Override public int read() throws IOException { checkOpen(); int read; if (position == streamPosition) { // Read ahead into buffer, for performance read = readAhead(buffer, 0, buffer.length); if (read >= 0) { read = buffer[0] & 0xff; } //System.out.println("Read 1 byte from stream: " + Integer.toHexString(read & 0xff)); } else { // ..or read byte from the cache syncPosition(); read = getCache().read(); //System.out.println("Read 1 byte from cache: " + Integer.toHexString(read & 0xff)); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { position++; } return read; }
private int readAhead(final byte[] pBytes, final int pOffset, final int pLength) throws IOException { int length; length = mStream.read(pBytes, pOffset, pLength); if (length > 0) { mStreamPosition += length; getCache().write(pBytes, pOffset, length); } return length; }
private int readAhead(final byte[] pBytes, final int pOffset, final int pLength) throws IOException { int length; length = stream.read(pBytes, pOffset, pLength); if (length > 0) { streamPosition += length; getCache().write(pBytes, pOffset, length); } return length; }
@Override public int read(byte[] pBytes, int pOffset, int pLength) throws IOException { checkOpen(); int length; if (position == streamPosition) { // Read bytes from the stream length = readAhead(pBytes, pOffset, pLength); //System.out.println("Read " + length + " byte from stream"); } else { // ...or read bytes from the cache syncPosition(); length = getCache().read(pBytes, pOffset, (int) Math.min(pLength, streamPosition - position)); //System.out.println("Read " + length + " byte from cache"); } // TODO: This field is not REALLY considered accessible.. :-P if (length > 0) { position += length; } return length; }
@Override public int read(byte[] pBytes, int pOffset, int pLength) throws IOException { checkOpen(); int length; if (mPosition == mStreamPosition) { // Read bytes from the stream length = readAhead(pBytes, pOffset, pLength); //System.out.println("Read " + length + " byte from stream"); } else { // ...or read bytes from the cache syncPosition(); length = getCache().read(pBytes, pOffset, (int) Math.min(pLength, mStreamPosition - mPosition)); //System.out.println("Read " + length + " byte from cache"); } // TODO: This field is not REALLY considered accessible.. :-P if (length > 0) { mPosition += length; } return length; }
@Override public int read() throws IOException { checkOpen(); int read; if (position == streamPosition) { // Read ahead into buffer, for performance read = readAhead(buffer, 0, buffer.length); if (read >= 0) { read = buffer[0] & 0xff; } //System.out.println("Read 1 byte from stream: " + Integer.toHexString(read & 0xff)); } else { // ..or read byte from the cache syncPosition(); read = getCache().read(); //System.out.println("Read 1 byte from cache: " + Integer.toHexString(read & 0xff)); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { position++; } return read; }
@Override public int read() throws IOException { checkOpen(); int read; if (mPosition == mStreamPosition) { // Read ahead into buffer, for performance read = readAhead(mBuffer, 0, mBuffer.length); if (read >= 0) { read = mBuffer[0] & 0xff; } //System.out.println("Read 1 byte from stream: " + Integer.toHexString(read & 0xff)); } else { // ..or read byte from the cache syncPosition(); read = getCache().read(); //System.out.println("Read 1 byte from cache: " + Integer.toHexString(read & 0xff)); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { mPosition++; } return read; }