Package com.twelvemonkeys.io
Class FileCacheSeekableStream
java.lang.Object
java.io.InputStream
com.twelvemonkeys.io.SeekableInputStream
com.twelvemonkeys.io.FileCacheSeekableStream
- All Implemented Interfaces:
Seekable,Closeable,AutoCloseable
A
SeekableInputStream implementation that caches data in a temporary File.
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InputStreamThe backing streamprotected longThe stream positon in the backing stream (stream)Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
markedPositions -
Constructor Summary
ConstructorsConstructorDescriptionFileCacheSeekableStream(InputStream pStream) Creates aFileCacheSeekableStreamreading from the givenInputStream.FileCacheSeekableStream(InputStream pStream, String pTempBaseName) Creates aFileCacheSeekableStreamreading from the givenInputStream.FileCacheSeekableStream(InputStream pStream, String pTempBaseName, File pTempDir) Creates aFileCacheSeekableStreamreading from the givenInputStream. -
Method Summary
Modifier and TypeMethodDescriptionintprotected voidprotected voidflushBeforeImpl(long pPosition) Discards the initial portion of the stream prior to the indicated postion.protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCachegetCache()final booleanisCached()Returns true if thisSeekablestream caches data itself in order to allow seeking backwards.final booleanReturns true if thisSeekablestream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.final booleanReturns 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 final voidMethods inherited from class com.twelvemonkeys.io.SeekableInputStream
checkOpen, close, finalize, flush, flushBefore, getFlushedPosition, getStreamPosition, mark, mark, markSupported, read, reset, seek, skipMethods 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
-
FileCacheSeekableStream
Creates aFileCacheSeekableStreamreading from the givenInputStream. Data will be cached in a temporary file.- Parameters:
pStream- theInputStreamto read from- Throws:
IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
FileCacheSeekableStream
Creates 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:
IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
FileCacheSeekableStream
public FileCacheSeekableStream(InputStream pStream, String pTempBaseName, File pTempDir) throws IOException Creates 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:
IOException- if the temporary file cannot be created, or cannot be opened for random access.
-
-
Method Details
-
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:
-
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:
-
closeImpl
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
getCache
protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache getCache() -
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
syncPosition
- Throws:
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:
-
seekImpl
- Specified by:
seekImplin classSeekableInputStream- Throws:
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:
-