Seekable
, Closeable
, AutoCloseable
public final class FileCacheSeekableStream extends SeekableInputStream
SeekableInputStream
implementation that caches data in a temporary File
.
Temporary files are created as specified in File.createTempFile(String, String, java.io.File)
.MemoryCacheSeekableStream
,
FileSeekableStream
,
File.createTempFile(String, String)
,
RandomAccessFile
Modifier and Type | Field | Description |
---|---|---|
protected InputStream |
stream |
The backing stream
|
protected long |
streamPosition |
The stream positon in the backing stream (stream)
|
markedPositions
Constructor | Description |
---|---|
FileCacheSeekableStream(InputStream pStream) |
Creates a
FileCacheSeekableStream reading from the given
InputStream . |
FileCacheSeekableStream(InputStream pStream,
String pTempBaseName) |
Creates a
FileCacheSeekableStream reading from the given
InputStream . |
FileCacheSeekableStream(InputStream pStream,
String pTempBaseName,
File pTempDir) |
Creates a
FileCacheSeekableStream reading from the given
InputStream . |
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
|
protected void |
closeImpl() |
|
protected void |
flushBeforeImpl(long pPosition) |
Discards the initial portion of the stream prior to the indicated postion.
|
protected com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache |
getCache() |
|
boolean |
isCached() |
Returns true if this
Seekable stream caches data itself in order
to allow seeking backwards. |
boolean |
isCachedFile() |
Returns true if this
Seekable stream caches data itself in
order to allow seeking backwards, and the cache is kept in a
temporary file. |
boolean |
isCachedMemory() |
Returns true if this
Seekable 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) |
|
protected void |
seekImpl(long pPosition) |
|
protected void |
syncPosition() |
readAllBytes, readNBytes, transferTo
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
checkOpen, close, finalize, flush, flushBefore, getFlushedPosition, getStreamPosition, mark, mark, markSupported, read, reset, seek, skip
protected final InputStream stream
protected long streamPosition
public FileCacheSeekableStream(InputStream pStream) throws IOException
FileCacheSeekableStream
reading from the given
InputStream
. Data will be cached in a temporary file.pStream
- the InputStream
to read fromIOException
- if the temporary file cannot be created,
or cannot be opened for random access.public FileCacheSeekableStream(InputStream pStream, String pTempBaseName) throws IOException
FileCacheSeekableStream
reading from the given
InputStream
. Data will be cached in a temporary file, with
the given base name.pStream
- the InputStream
to read frompTempBaseName
- optional base name for the temporary fileIOException
- if the temporary file cannot be created,
or cannot be opened for random access.public FileCacheSeekableStream(InputStream pStream, String pTempBaseName, File pTempDir) throws IOException
FileCacheSeekableStream
reading from the given
InputStream
. Data will be cached in a temporary file, with
the given base name, in the given directorypStream
- the InputStream
to read frompTempBaseName
- optional base name for the temporary filepTempDir
- optional temp directoryIOException
- if the temporary file cannot be created,
or cannot be opened for random access.public final boolean isCachedMemory()
Seekable
Seekable
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.isCachedMemory
in interface Seekable
true
if this Seekable
caches data in main
memory.Seekable.isCached()
,
Seekable.isCachedFile()
public final boolean isCachedFile()
Seekable
Seekable
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.isCachedFile
in interface Seekable
true
if this Seekable
caches data in a
temporary file.Seekable.isCached()
,
Seekable.isCachedMemory()
protected void closeImpl() throws IOException
IOException
public int read() throws IOException
IOException
public int read(byte[] pBytes, int pOffset, int pLength) throws IOException
IOException
protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache getCache()
public int available() throws IOException
available
in class InputStream
IOException
protected final void syncPosition() throws IOException
IOException
public final boolean isCached()
Seekable
Seekable
stream 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.true
if this Seekable
caches data.Seekable.isCachedMemory()
,
Seekable.isCachedFile()
protected void seekImpl(long pPosition) throws IOException
seekImpl
in class SeekableInputStream
IOException
protected void flushBeforeImpl(long pPosition)
SeekableInputStream
flushBeforeImpl
in class SeekableInputStream
pPosition
- the position to flush toSeekableInputStream.flushBefore(long)
Copyright © 2018. All rights reserved.