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 = stream.read(pBytes, pOffset, pLength); if (length > 0) { streamPosition += length; cache.write(pBytes, pOffset, length); } } else { // ...or read bytes from the cache syncPosition(); length = cache.read(pBytes, pOffset, pLength); } // TODO: This field is not REALLY considered accessible.. :-P if (length > 0) { position += length; } return length; }
public int read() throws IOException { checkOpen(); int read; if (position == streamPosition) { // TODO: Read more bytes here! // TODO: Use buffer if not in-memory cache? (See FileCacheSeekableStream overrides). // Read a byte from the stream read = stream.read(); if (read >= 0) { streamPosition++; cache.write(read); } } else { // ..or read byte from the cache syncPosition(); read = cache.read(); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { position++; } return read; }
mCache.write(buffer, 0, read); mStreamPosition += read; left -= read;
cache.write(buffer, 0, read); streamPosition += read; left -= read;
public int read() throws IOException { checkOpen(); int read; if (mPosition == mStreamPosition) { // TODO: Read more bytes here! // TODO: Use buffer if not in-memory cache? (See FileCacheSeekableStream overrides). // Read a byte from the stream read = mStream.read(); if (read >= 0) { mStreamPosition++; mCache.write(read); } } else { // ..or read byte from the cache syncPosition(); read = mCache.read(); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { mPosition++; } return read; }
public int read() throws IOException { checkOpen(); int read; if (position == streamPosition) { // TODO: Read more bytes here! // TODO: Use buffer if not in-memory cache? (See FileCacheSeekableStream overrides). // Read a byte from the stream read = stream.read(); if (read >= 0) { streamPosition++; cache.write(read); } } else { // ..or read byte from the cache syncPosition(); read = cache.read(); } // TODO: This field is not REALLY considered accessible.. :-P if (read != -1) { position++; } return read; }
@Override public int read(byte[] pBytes, int pOffset, int pLength) throws IOException { checkOpen(); int length; if (position == streamPosition) { // Read bytes from the stream length = stream.read(pBytes, pOffset, pLength); if (length > 0) { streamPosition += length; cache.write(pBytes, pOffset, length); } } else { // ...or read bytes from the cache syncPosition(); length = cache.read(pBytes, pOffset, pLength); } // 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 = mStream.read(pBytes, pOffset, pLength); if (length > 0) { mStreamPosition += length; mCache.write(pBytes, pOffset, length); } } else { // ...or read bytes from the cache syncPosition(); length = mCache.read(pBytes, pOffset, pLength); } // TODO: This field is not REALLY considered accessible.. :-P if (length > 0) { mPosition += length; } return length; }
/** * Writes a series of bytes at the current read/write position. The read/write position will be increased by * {@code pLength}. * <p/> * This implementation invokes {@link #write(int)} {@code pLength} times. * Subclasses may override this method for performance. * * @param pBuffer the bytes to write. * @param pOffset the starting offset into the buffer. * @param pLength the number of bytes to write from the buffer. * * @throws IOException if an I/O exception occurs in the cache backing mechanism. */ void write(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { for (int i = 0; i < pLength; i++) { write(pBuffer[pOffset + i]); } }
/** * Writes a series of bytes at the current read/write position. The read/write position will be increased by * {@code pLength}. * <p/> * This implementation invokes {@link #write(int)} {@code pLength} times. * Subclasses may override this method for performance. * * @param pBuffer the bytes to write. * @param pOffset the starting offset into the buffer. * @param pLength the number of bytes to write from the buffer. * * @throws IOException if an I/O exception occurs in the cache backing mechanism. */ void write(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { for (int i = 0; i < pLength; i++) { write(pBuffer[pOffset + i]); } }
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; }
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; }
cache.write(buffer, 0, read); streamPosition += read; left -= read;
/** * Writes a series of bytes at the current read/write position. The read/write position will be increased by * {@code pLength}. * <p/> * This implementation invokes {@link #write(int)} {@code pLength} times. * Subclasses may override this method for performance. * * @param pBuffer the bytes to write. * @param pOffset the starting offset into the buffer. * @param pLength the number of bytes to write from the buffer. * * @throws IOException if an I/O exception occurs in the cache backing mechanism. */ void write(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { for (int i = 0; i < pLength; i++) { write(pBuffer[pOffset + i]); } }