Package com.twelvemonkeys.io
Class FileCacheSeekableStream
- java.lang.Object
-
- java.io.InputStream
-
- com.twelvemonkeys.io.SeekableInputStream
-
- com.twelvemonkeys.io.FileCacheSeekableStream
-
- All Implemented Interfaces:
Seekable,java.io.Closeable,java.lang.AutoCloseable
public final class FileCacheSeekableStream extends SeekableInputStream
ASeekableInputStreamimplementation that caches data in a temporaryFile.Temporary files are created as specified in
File.createTempFile(String, String, java.io.File).- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/FileCacheSeekableStream.java#5 $
- Author:
- Harald Kuhr
- See Also:
MemoryCacheSeekableStream,FileSeekableStream,File.createTempFile(String, String),RandomAccessFile
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.InputStreamstreamThe backing streamprotected longstreamPositionThe stream positon in the backing stream (stream)-
Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
markedPositions
-
-
Constructor Summary
Constructors Constructor Description FileCacheSeekableStream(java.io.InputStream pStream)Creates aFileCacheSeekableStreamreading from the givenInputStream.FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName)Creates aFileCacheSeekableStreamreading from the givenInputStream.FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName, java.io.File pTempDir)Creates aFileCacheSeekableStreamreading from the givenInputStream.
-
Method Summary
All Methods Instance 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 com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCachegetCache()booleanisCached()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards.booleanisCachedFile()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.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
-
-
-
-
Constructor Detail
-
FileCacheSeekableStream
public FileCacheSeekableStream(java.io.InputStream pStream) throws java.io.IOExceptionCreates aFileCacheSeekableStreamreading from the givenInputStream. Data will be cached in a temporary file.- Parameters:
pStream- theInputStreamto read from- Throws:
java.io.IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
FileCacheSeekableStream
public FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName) throws java.io.IOExceptionCreates aFileCacheSeekableStreamreading from the givenInputStream. Data will be cached in a temporary file, with the given base name.- Parameters:
pStream- theInputStreamto read frompTempBaseName- optional base name for the temporary file- Throws:
java.io.IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
FileCacheSeekableStream
public FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName, java.io.File pTempDir) throws java.io.IOExceptionCreates aFileCacheSeekableStreamreading from the givenInputStream. Data will be cached in a temporary file, with the given base name, in the given directory- Parameters:
pStream- theInputStreamto read frompTempBaseName- optional base name for the temporary filepTempDir- optional temp directory- Throws:
java.io.IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
-
Method Detail
-
isCachedMemory
public final 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.- Specified by:
isCachedMemoryin interfaceSeekable- Returns:
trueif thisSeekablecaches data in main memory.- See Also:
Seekable.isCached(),Seekable.isCachedFile()
-
isCachedFile
public final 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.- Specified by:
isCachedFilein interfaceSeekable- Returns:
trueif thisSeekablecaches data in a temporary file.- See Also:
Seekable.isCached(),Seekable.isCachedMemory()
-
closeImpl
protected void closeImpl() throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException- Throws:
java.io.IOException
-
getCache
protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache getCache()
-
available
public int available() throws java.io.IOException- Overrides:
availablein 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()
-
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)
-
-