Package com.twelvemonkeys.io
Class AbstractCachedSeekableStream
- java.lang.Object
-
- java.io.InputStream
-
- com.twelvemonkeys.io.SeekableInputStream
-
- com.twelvemonkeys.io.AbstractCachedSeekableStream
-
- All Implemented Interfaces:
Seekable,java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
FileCacheSeekableStream,MemoryCacheSeekableStream
abstract class AbstractCachedSeekableStream extends SeekableInputStream
Represents a cached seekable stream, that reads through a cache.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/AbstractCachedSeekableStream.java#2 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAbstractCachedSeekableStream.StreamCacheAn abstract stream cache.
-
Field Summary
Fields Modifier and Type Field Description private AbstractCachedSeekableStream.StreamCachecacheprotected java.io.InputStreamstreamThe backing streamprotected longstreamPositionThe stream positon in the backing stream (stream)-
Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
closed, flushedPosition, markedPositions, position
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCachedSeekableStream(java.io.InputStream pStream, AbstractCachedSeekableStream.StreamCache pCache)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intavailable()protected voidcloseImpl()protected voidflushBeforeImpl(long pPosition)Discards the initial portion of the stream prior to the indicated postion.protected AbstractCachedSeekableStream.StreamCachegetCache()booleanisCached()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards.abstract booleanisCachedFile()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.abstract booleanisCachedMemory()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards, and the cache is kept in main memory.intread()intread(byte[] pBytes, int pOffset, int pLength)protected voidseekImpl(long pPosition)protected voidsyncPosition()-
Methods inherited from class com.twelvemonkeys.io.SeekableInputStream
checkOpen, close, finalize, flush, flushBefore, getFlushedPosition, getStreamPosition, mark, mark, markSupported, read, reset, seek, skip
-
-
-
-
Field Detail
-
stream
protected final java.io.InputStream stream
The backing stream
-
streamPosition
protected long streamPosition
The stream positon in the backing stream (stream)
-
cache
private AbstractCachedSeekableStream.StreamCache cache
-
-
Constructor Detail
-
AbstractCachedSeekableStream
protected AbstractCachedSeekableStream(java.io.InputStream pStream, AbstractCachedSeekableStream.StreamCache pCache)
-
-
Method Detail
-
getCache
protected final AbstractCachedSeekableStream.StreamCache getCache()
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
syncPosition
protected final void syncPosition() throws java.io.IOException- Throws:
java.io.IOException
-
isCached
public final boolean isCached()
Description copied from interface:SeekableReturns true if thisSeekablestream 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:
trueif thisSeekablecaches data.- See Also:
Seekable.isCachedMemory(),Seekable.isCachedFile()
-
isCachedMemory
public abstract boolean isCachedMemory()
Description copied from interface:SeekableReturns true if thisSeekablestream 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.- Returns:
trueif thisSeekablecaches data in main memory.- See Also:
Seekable.isCached(),Seekable.isCachedFile()
-
isCachedFile
public abstract boolean isCachedFile()
Description copied from interface:SeekableReturns true if thisSeekablestream 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.- Returns:
trueif thisSeekablecaches data in a temporary file.- See Also:
Seekable.isCached(),Seekable.isCachedMemory()
-
seekImpl
protected void seekImpl(long pPosition) throws java.io.IOException- Specified by:
seekImplin classSeekableInputStream- Throws:
java.io.IOException
-
flushBeforeImpl
protected void flushBeforeImpl(long pPosition)
Description copied from class:SeekableInputStreamDiscards the initial portion of the stream prior to the indicated postion.- Specified by:
flushBeforeImplin classSeekableInputStream- Parameters:
pPosition- the position to flush to- See Also:
SeekableInputStream.flushBefore(long)
-
closeImpl
protected void closeImpl() throws java.io.IOException- Specified by:
closeImplin classSeekableInputStream- Throws:
java.io.IOException
-
-