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
ASeekableInputStream
implementation 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 class
FileCacheSeekableStream.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 aFileCacheSeekableStream
reading from the givenInputStream
.FileCacheSeekableStream(java.io.InputStream pStream, java.io.File pFile)
FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName)
Creates aFileCacheSeekableStream
reading from the givenInputStream
.FileCacheSeekableStream(java.io.InputStream pStream, java.lang.String pTempBaseName, java.io.File pTempDir)
Creates aFileCacheSeekableStream
reading from the givenInputStream
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeImpl()
(package private) static java.io.File
createTempFile(java.lang.String pTempBaseName, java.io.File pTempDir)
boolean
isCachedFile()
Returns true if thisSeekable
stream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.boolean
isCachedMemory()
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
-
-
-
-
Constructor Detail
-
FileCacheSeekableStream
public FileCacheSeekableStream(java.io.InputStream pStream) throws java.io.IOException
Creates aFileCacheSeekableStream
reading from the givenInputStream
. Data will be cached in a temporary file.- Parameters:
pStream
- theInputStream
to 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.IOException
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:
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.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:
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: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:
Seekable.isCached()
,Seekable.isCachedFile()
-
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:
Seekable.isCached()
,Seekable.isCachedMemory()
-
closeImpl
protected void closeImpl() throws java.io.IOException
- Overrides:
closeImpl
in classAbstractCachedSeekableStream
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classAbstractCachedSeekableStream
- Throws:
java.io.IOException
-
read
public int read(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException
- Overrides:
read
in classAbstractCachedSeekableStream
- Throws:
java.io.IOException
-
readAhead
private int readAhead(byte[] pBytes, int pOffset, int pLength) throws java.io.IOException
- Throws:
java.io.IOException
-
-