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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
close()
void
flush
(long pPosition) Optionally flushes any data prior to the given position.private byte[]
getBlock()
long
Returns the current cache read/write position.int
read()
Reads a single byte a the current read/write position.int
read
(byte[] pBytes, int pOffset, int pLength) Writes a series of bytes at the current read/write position.void
seek
(long pPosition) Repositions the current cache read/write position to the given position.void
write
(byte[] pBuffer, int pOffset, int pLength) Writes a series of bytes at the current read/write position.void
write
(int pByte) Writes a single byte at the current read/write position.
-
Field Details
-
BLOCK_SIZE
static final int BLOCK_SIZE- See Also:
-
cache
-
length
private long length -
position
private long position -
start
private long start
-
-
Constructor Details
-
MemoryCache
MemoryCache()
-
-
Method Details
-
getBlock
- Throws:
IOException
-
write
Description copied from class:AbstractCachedSeekableStream.StreamCache
Writes a single byte at the current read/write position. The read/write position will be increased by one.- Specified by:
write
in classAbstractCachedSeekableStream.StreamCache
- Parameters:
pByte
- the byte value to write.- Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
write
Description copied from class:AbstractCachedSeekableStream.StreamCache
Writes 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)
pLength
times. Subclasses may override this method for performance.- Overrides:
write
in 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:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
read
Description copied from class:AbstractCachedSeekableStream.StreamCache
Reads a single byte a the current read/write position. The read/write position will be increased by one.- Specified by:
read
in classAbstractCachedSeekableStream.StreamCache
- Returns:
- the value read, or
-1
to indicate EOF. - Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
read
Description copied from class:AbstractCachedSeekableStream.StreamCache
Writes a series of bytes at the current read/write position. The read/write position will be increased bypLength
.This implementation invokes
AbstractCachedSeekableStream.StreamCache.read()
pLength
times. Subclasses may override this method for performance.- Overrides:
read
in 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
-1
to indicate EOF. - Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
seek
Description copied from class:AbstractCachedSeekableStream.StreamCache
Repositions the current cache read/write position to the given position.- Specified by:
seek
in classAbstractCachedSeekableStream.StreamCache
- Parameters:
pPosition
- the new read/write position- Throws:
IOException
- if an I/O exception occurs in the cache backing mechanism.
-
flush
public void flush(long pPosition) Description copied from class:AbstractCachedSeekableStream.StreamCache
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.
- Overrides:
flush
in classAbstractCachedSeekableStream.StreamCache
- Parameters:
pPosition
- the last position to flush.
-
close
- Specified by:
close
in classAbstractCachedSeekableStream.StreamCache
- Throws:
IOException
-
getPosition
public long getPosition()Description copied from class:AbstractCachedSeekableStream.StreamCache
Returns the current cache read/write position.- Specified by:
getPosition
in classAbstractCachedSeekableStream.StreamCache
- Returns:
- the current cache read/write postion.
-