Package com.twelvemonkeys.io
Class AbstractCachedSeekableStream.StreamCache
- java.lang.Object
-
- com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache
-
- Direct Known Subclasses:
FileCacheSeekableStream.FileCache,MemoryCacheSeekableStream.MemoryCache
- Enclosing class:
- AbstractCachedSeekableStream
abstract static class AbstractCachedSeekableStream.StreamCache extends java.lang.ObjectAn abstract stream cache.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/AbstractCachedSeekableStream.java#2 $
-
-
Constructor Summary
Constructors Constructor Description StreamCache()Creates aStreamCache.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract voidclose()(package private) voidflush(long pPosition)Optionally flushes any data prior to the given position.(package private) abstract longgetPosition()Returns the current cache read/write position.(package private) abstract intread()Reads a single byte a the current read/write position.(package private) intread(byte[] pBuffer, int pOffset, int pLength)Writes a series of bytes at the current read/write position.(package private) abstract voidseek(long pPosition)Repositions the current cache read/write position to the given position.(package private) voidwrite(byte[] pBuffer, int pOffset, int pLength)Writes a series of bytes at the current read/write position.(package private) abstract voidwrite(int pByte)Writes a single byte at the current read/write position.
-
-
-
Method Detail
-
write
abstract void write(int pByte) throws java.io.IOExceptionWrites a single byte at the current read/write position. The read/write position will be increased by one.- Parameters:
pByte- the byte value to write.- Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
write
void write(byte[] pBuffer, int pOffset, int pLength) throws java.io.IOExceptionWrites a series of bytes at the current read/write position. The read/write position will be increased bypLength.This implementation invokes
write(int)pLengthtimes. Subclasses may override this method for performance.- Parameters:
pBuffer- the bytes to write.pOffset- the starting offset into the buffer.pLength- the number of bytes to write from the buffer.- Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
read
abstract int read() throws java.io.IOExceptionReads a single byte a the current read/write position. The read/write position will be increased by one.- Returns:
- the value read, or
-1to indicate EOF. - Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
read
int read(byte[] pBuffer, int pOffset, int pLength) throws java.io.IOExceptionWrites a series of bytes at the current read/write position. The read/write position will be increased bypLength.This implementation invokes
read()pLengthtimes. Subclasses may override this method for performance.- Parameters:
pBuffer- the bytes to writepOffset- the starting offset into the buffer.pLength- the number of bytes to write from the buffer.- Returns:
- the number of bytes read, or
-1to indicate EOF. - Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
seek
abstract void seek(long pPosition) throws java.io.IOExceptionRepositions the current cache read/write position to the given position.- Parameters:
pPosition- the new read/write position- Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
flush
void flush(long pPosition)
Optionally flushes any data prior to the given position.Attempting to perform a seek operation, and/or a read or write operation to a position equal to or before the flushed position may result in exceptions or undefined behaviour.
Subclasses should override this method for performance reasons, to avoid holding on to unnecessary resources. This implementation does nothing.
- Parameters:
pPosition- the last position to flush.
-
getPosition
abstract long getPosition() throws java.io.IOExceptionReturns the current cache read/write position.- Returns:
- the current cache read/write postion.
- Throws:
java.io.IOException- if the position can't be determined because of a problem in the cache backing mechanism.
-
close
abstract void close() throws java.io.IOException- Throws:
java.io.IOException
-
-