Package com.twelvemonkeys.io
Class MemoryCacheSeekableStream.MemoryCache
- java.lang.Object
-
- com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache
-
- com.twelvemonkeys.io.MemoryCacheSeekableStream.MemoryCache
-
- Enclosing class:
- MemoryCacheSeekableStream
static final class MemoryCacheSeekableStream.MemoryCache extends AbstractCachedSeekableStream.StreamCache
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intBLOCK_SIZEprivate java.util.List<byte[]>cacheprivate longlengthprivate longpositionprivate longstart
-
Constructor Summary
Constructors Constructor Description MemoryCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidclose()voidflush(long pPosition)Optionally flushes any data prior to the given position.private byte[]getBlock()longgetPosition()Returns the current cache read/write position.intread()Reads a single byte a the current read/write position.intread(byte[] pBytes, int pOffset, int pLength)Writes a series of bytes at the current read/write position.voidseek(long pPosition)Repositions the current cache read/write position to the given position.voidwrite(byte[] pBuffer, int pOffset, int pLength)Writes a series of bytes at the current read/write position.voidwrite(int pByte)Writes a single byte at the current read/write position.
-
-
-
Field Detail
-
BLOCK_SIZE
static final int BLOCK_SIZE
- See Also:
- Constant Field Values
-
cache
private final java.util.List<byte[]> cache
-
length
private long length
-
position
private long position
-
start
private long start
-
-
Method Detail
-
getBlock
private byte[] getBlock() throws java.io.IOException- Throws:
java.io.IOException
-
write
public void write(int pByte) throws java.io.IOExceptionDescription copied from class:AbstractCachedSeekableStream.StreamCacheWrites a single byte at the current read/write position. The read/write position will be increased by one.- Specified by:
writein classAbstractCachedSeekableStream.StreamCache- Parameters:
pByte- the byte value to write.- Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
write
public void write(byte[] pBuffer, int pOffset, int pLength) throws java.io.IOExceptionDescription copied from class:AbstractCachedSeekableStream.StreamCacheWrites a series of bytes at the current read/write position. The read/write position will be increased bypLength.This implementation invokes
AbstractCachedSeekableStream.StreamCache.write(int)pLengthtimes. Subclasses may override this method for performance.- Overrides:
writein classAbstractCachedSeekableStream.StreamCache- 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
public int read() throws java.io.IOExceptionDescription copied from class:AbstractCachedSeekableStream.StreamCacheReads a single byte a the current read/write position. The read/write position will be increased by one.- Specified by:
readin classAbstractCachedSeekableStream.StreamCache- Returns:
- the value read, or
-1to indicate EOF. - Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
read
public int read(byte[] pBytes, int pOffset, int pLength) throws java.io.IOExceptionDescription copied from class:AbstractCachedSeekableStream.StreamCacheWrites a series of bytes at the current read/write position. The read/write position will be increased bypLength.This implementation invokes
AbstractCachedSeekableStream.StreamCache.read()pLengthtimes. Subclasses may override this method for performance.- Overrides:
readin classAbstractCachedSeekableStream.StreamCache- Parameters:
pBytes- 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
public void seek(long pPosition) throws java.io.IOExceptionDescription copied from class:AbstractCachedSeekableStream.StreamCacheRepositions the current cache read/write position to the given position.- Specified by:
seekin classAbstractCachedSeekableStream.StreamCache- Parameters:
pPosition- the new read/write position- Throws:
java.io.IOException- if an I/O exception occurs in the cache backing mechanism.
-
flush
public void flush(long pPosition)
Description copied from class:AbstractCachedSeekableStream.StreamCacheOptionally 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.
- Overrides:
flushin classAbstractCachedSeekableStream.StreamCache- Parameters:
pPosition- the last position to flush.
-
close
void close() throws java.io.IOException- Specified by:
closein classAbstractCachedSeekableStream.StreamCache- Throws:
java.io.IOException
-
getPosition
public long getPosition()
Description copied from class:AbstractCachedSeekableStream.StreamCacheReturns the current cache read/write position.- Specified by:
getPositionin classAbstractCachedSeekableStream.StreamCache- Returns:
- the current cache read/write postion.
-
-