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,java.io.Closeable,java.lang.AutoCloseable
public final class FileCacheSeekableStream extends AbstractCachedSeekableStream
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 $
- See Also:
MemoryCacheSeekableStream,FileSeekableStream,File.createTempFile(String, String),RandomAccessFile
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classFileCacheSeekableStream.FileCache-
Nested classes/interfaces inherited from class com.twelvemonkeys.io.AbstractCachedSeekableStream
AbstractCachedSeekableStream.StreamCache
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]buffer-
Fields inherited from class com.twelvemonkeys.io.AbstractCachedSeekableStream
stream, streamPosition
-
Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
closed, flushedPosition, markedPositions, position
-
-
Constructor Summary
Constructors Constructor Description FileCacheSeekableStream(java.io.InputStream pStream)Creates aFileCacheSeekableStreamreading from the givenInputStream.FileCacheSeekableStream(java.io.InputStream pStream, java.io.File pFile)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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseImpl()(package private) static java.io.FilecreateTempFile(java.lang.String pTempBaseName, java.io.File pTempDir)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)private intreadAhead(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
-
-
-
-
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.
-
FileCacheSeekableStream
FileCacheSeekableStream(java.io.InputStream pStream, java.io.File pFile) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
-
Method Detail
-
createTempFile
static java.io.File createTempFile(java.lang.String pTempBaseName, java.io.File pTempDir) throws java.io.IOException- Throws:
java.io.IOException
-
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- Specified by:
isCachedMemoryin classAbstractCachedSeekableStream- 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- Specified by:
isCachedFilein classAbstractCachedSeekableStream- Returns:
trueif thisSeekablecaches data in a temporary file.- See Also:
Seekable.isCached(),Seekable.isCachedMemory()
-
closeImpl
protected void closeImpl() throws java.io.IOException- Overrides:
closeImplin classAbstractCachedSeekableStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Overrides:
readin classAbstractCachedSeekableStream- Throws:
java.io.IOException
-
read
public int read(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException- Overrides:
readin classAbstractCachedSeekableStream- Throws:
java.io.IOException
-
readAhead
private int readAhead(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException- Throws:
java.io.IOException
-
-