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
An 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 -
Method Summary
Modifier and TypeMethodDescription(package private) abstract void
close()
(package private) void
flush
(long pPosition) Optionally flushes any data prior to the given position.(package private) abstract long
Returns the current cache read/write position.(package private) abstract int
read()
Reads a single byte a the current read/write position.(package private) int
read
(byte[] pBuffer, int pOffset, int pLength) Writes a series of bytes at the current read/write position.(package private) abstract void
seek
(long pPosition) Repositions the current cache read/write position to the given position.(package private) void
write
(byte[] pBuffer, int pOffset, int pLength) Writes a series of bytes at the current read/write position.(package private) abstract void
write
(int pByte) Writes a single byte at the current read/write position.
-
Constructor Details
-
StreamCache
StreamCache()Creates aStreamCache
.
-
-
Method Details
-
write
Writes 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:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
write
Writes a series of bytes at the current read/write position. The read/write position will be increased bypLength
.This implementation invokes
write(int)
pLength
times. 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:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
read
Reads a single byte a the current read/write position. The read/write position will be increased by one.- Returns:
- the value read, or
-1
to indicate EOF. - Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
read
Writes a series of bytes at the current read/write position. The read/write position will be increased bypLength
.This implementation invokes
read()
pLength
times. 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
-1
to indicate EOF. - Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
seek
Repositions the current cache read/write position to the given position.- Parameters:
pPosition
- the new read/write position- Throws:
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
Returns the current cache read/write position.- Returns:
- the current cache read/write postion.
- Throws:
IOException
- if the position can't be determined because of a problem in the cache backing mechanism.
-
close
- Throws:
IOException
-