Package com.twelvemonkeys.io
Class FileCacheSeekableStream
java.lang.Object
java.io.InputStream
com.twelvemonkeys.io.SeekableInputStream
com.twelvemonkeys.io.AbstractCachedSeekableStream
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 $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Nested classes/interfaces inherited from class com.twelvemonkeys.io.AbstractCachedSeekableStream
AbstractCachedSeekableStream.StreamCache
-
Field Summary
FieldsFields inherited from class com.twelvemonkeys.io.AbstractCachedSeekableStream
stream, streamPosition
Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
closed, flushedPosition, markedPositions, position
-
Constructor Summary
ConstructorsConstructorDescriptionFileCacheSeekableStream
(InputStream pStream) Creates aFileCacheSeekableStream
reading from the givenInputStream
.FileCacheSeekableStream
(InputStream pStream, File pFile) FileCacheSeekableStream
(InputStream pStream, String pTempBaseName) Creates aFileCacheSeekableStream
reading from the givenInputStream
.FileCacheSeekableStream
(InputStream pStream, String pTempBaseName, File pTempDir) Creates aFileCacheSeekableStream
reading from the givenInputStream
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
(package private) static File
createTempFile
(String pTempBaseName, File pTempDir) 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) private int
readAhead
(byte[] pBytes, int pOffset, int pLength) Methods inherited from class com.twelvemonkeys.io.AbstractCachedSeekableStream
available, flushBeforeImpl, getCache, isCached, seekImpl, syncPosition
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
-
buffer
private byte[] buffer
-
-
Constructor Details
-
FileCacheSeekableStream
Creates aFileCacheSeekableStream
reading from the givenInputStream
. Data will be cached in a temporary file.- Parameters:
pStream
- theInputStream
to read from- Throws:
IOException
- if the temporary file cannot be created, or cannot be opened for random access.
-
FileCacheSeekableStream
Creates aFileCacheSeekableStream
reading from the givenInputStream
. Data will be cached in a temporary file, with the given base name.- Parameters:
pStream
- theInputStream
to 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 aFileCacheSeekableStream
reading from the givenInputStream
. Data will be cached in a temporary file, with the given base name, in the given directory- Parameters:
pStream
- theInputStream
to 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.
-
FileCacheSeekableStream
FileCacheSeekableStream(InputStream pStream, File pFile) throws FileNotFoundException - Throws:
FileNotFoundException
-
-
Method Details
-
createTempFile
- Throws:
IOException
-
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
- Specified by:
isCachedMemory
in classAbstractCachedSeekableStream
- 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
- Specified by:
isCachedFile
in classAbstractCachedSeekableStream
- Returns:
true
if thisSeekable
caches data in a temporary file.- See Also:
-
closeImpl
- Overrides:
closeImpl
in classAbstractCachedSeekableStream
- Throws:
IOException
-
read
- Overrides:
read
in classAbstractCachedSeekableStream
- Throws:
IOException
-
read
- Overrides:
read
in classAbstractCachedSeekableStream
- Throws:
IOException
-
readAhead
- Throws:
IOException
-