Package com.twelvemonkeys.io
Class MemoryCacheSeekableStream
java.lang.Object
java.io.InputStream
com.twelvemonkeys.io.SeekableInputStream
com.twelvemonkeys.io.MemoryCacheSeekableStream
- All Implemented Interfaces:
Seekable
,Closeable
,AutoCloseable
A
SeekableInputStream
implementation that caches data in memory.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/MemoryCacheSeekableStream.java#3 $
- Author:
- Harald Kuhr
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InputStream
The backing streamprotected long
The stream positon in the backing stream (stream)Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
markedPositions
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryCacheSeekableStream
(InputStream pStream) Creates aMemoryCacheSeekableStream
, reading from the givenInputStream
. -
Method Summary
Modifier and TypeMethodDescriptionint
protected void
protected void
flushBeforeImpl
(long pPosition) Discards the initial portion of the stream prior to the indicated postion.protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache
getCache()
final boolean
isCached()
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards.final boolean
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.final boolean
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards, and the cache is kept in main memory.int
read()
int
read
(byte[] pBytes, int pOffset, int pLength) protected void
seekImpl
(long pPosition) protected final void
Methods inherited from class com.twelvemonkeys.io.SeekableInputStream
checkOpen, close, finalize, flush, flushBefore, getFlushedPosition, getStreamPosition, mark, mark, markSupported, read, reset, seek, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
stream
The backing stream -
streamPosition
protected long streamPositionThe stream positon in the backing stream (stream)
-
-
Constructor Details
-
MemoryCacheSeekableStream
Creates aMemoryCacheSeekableStream
, reading from the givenInputStream
. Data will be cached in memory.- Parameters:
pStream
- theInputStream
to read from.
-
-
Method Details
-
isCachedMemory
public final boolean isCachedMemory()Description copied from interface:Seekable
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards, and the cache is kept in main memory. Applications may consult this in order to decide how frequently, or whether, to flush in order to conserve cache resources.- Specified by:
isCachedMemory
in interfaceSeekable
- Returns:
true
if thisSeekable
caches data in main memory.- See Also:
-
isCachedFile
public final boolean isCachedFile()Description copied from interface:Seekable
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file. Applications may consult this in order to decide how frequently, or whether, to flush in order to conserve cache resources.- Specified by:
isCachedFile
in interfaceSeekable
- Returns:
true
if thisSeekable
caches data in a temporary file.- See Also:
-
getCache
protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache getCache() -
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
syncPosition
- Throws:
IOException
-
isCached
public final boolean isCached()Description copied from interface:Seekable
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards. Applications may consult this in order to decide how frequently, or whether, to flush in order to conserve cache resources.- Returns:
true
if thisSeekable
caches data.- See Also:
-
seekImpl
- Specified by:
seekImpl
in classSeekableInputStream
- Throws:
IOException
-
flushBeforeImpl
protected void flushBeforeImpl(long pPosition) Description copied from class:SeekableInputStream
Discards the initial portion of the stream prior to the indicated postion.- Specified by:
flushBeforeImpl
in classSeekableInputStream
- Parameters:
pPosition
- the position to flush to- See Also:
-
closeImpl
- Specified by:
closeImpl
in classSeekableInputStream
- Throws:
IOException
-