protected void seekImpl(long pPosition) throws IOException { if (streamPosition < pPosition) { if (cache.getPosition() != streamPosition) { cache.seek(streamPosition); cache.write(buffer, 0, read); streamPosition += read; left -= read; cache.seek(pPosition);
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; }
protected void closeImpl() throws IOException { cache.close(); cache = null; stream.close(); }
protected void seekImpl(long pPosition) throws IOException { if (mStreamPosition < pPosition) { if (mCache.getPosition() != mStreamPosition) { mCache.seek(mStreamPosition); mCache.write(buffer, 0, read); mStreamPosition += read; left -= read; mCache.seek(pPosition);
protected void seekImpl(long pPosition) throws IOException { if (streamPosition < pPosition) { if (cache.getPosition() != streamPosition) { cache.seek(streamPosition); cache.write(buffer, 0, read); streamPosition += read; left -= read; cache.seek(pPosition);
/** * 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 #read()} {@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. * @return the number of bytes read, or {@code -1} to indicate EOF. * * @throws IOException if an I/O exception occurs in the cache backing mechanism. */ int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { int count = 0; for (int i = 0; i < pLength; i++) { int read = read(); if (read >= 0) { pBuffer[pOffset + i] = (byte) read; count++; } else { break; } } return count; }
/** * 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 #read()} {@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. * @return the number of bytes read, or {@code -1} to indicate EOF. * * @throws IOException if an I/O exception occurs in the cache backing mechanism. */ int read(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException { int count = 0; for (int i = 0; i < pLength; i++) { int read = read(); if (read >= 0) { pBuffer[pOffset + i] = (byte) read; count++; } else { break; } } return count; }
@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; }
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() 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(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; }
@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(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; }
/** * 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]); } }
protected void flushBeforeImpl(long pPosition) { cache.flush(pPosition); }
protected void flushBeforeImpl(long pPosition) { mCache.flush(pPosition); }
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; }