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.Object
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 Constructor Description StreamCache()
Creates aStreamCache
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract void
close()
(package private) void
flush(long pPosition)
Optionally flushes any data prior to the given position.(package private) abstract long
getPosition()
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.
-
-
-
Method Detail
-
write
abstract void write(int pByte) throws java.io.IOException
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:
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.IOException
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:
java.io.IOException
- if an I/O exception occurs in the cache backing mechanism.
-
read
abstract int read() throws java.io.IOException
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:
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.IOException
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:
java.io.IOException
- if an I/O exception occurs in the cache backing mechanism.
-
seek
abstract void seek(long pPosition) throws java.io.IOException
Repositions 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.IOException
Returns 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
-
-