Class FileCacheSeekableStream

All Implemented Interfaces:
Seekable, Closeable, AutoCloseable

public final class FileCacheSeekableStream extends SeekableInputStream
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 Details

    • stream

      protected final InputStream stream
      The backing stream
    • streamPosition

      protected long streamPosition
      The stream positon in the backing stream (stream)
  • Constructor Details

    • FileCacheSeekableStream

      public FileCacheSeekableStream(InputStream pStream) throws IOException
      Creates a FileCacheSeekableStream reading from the given InputStream. Data will be cached in a temporary file.
      Parameters:
      pStream - the InputStream to read from
      Throws:
      IOException - if the temporary file cannot be created, or cannot be opened for random access.
    • FileCacheSeekableStream

      public FileCacheSeekableStream(InputStream pStream, String pTempBaseName) throws IOException
      Creates a FileCacheSeekableStream reading from the given InputStream. Data will be cached in a temporary file, with the given base name.
      Parameters:
      pStream - the InputStream to read from
      pTempBaseName - 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 a FileCacheSeekableStream reading from the given InputStream. Data will be cached in a temporary file, with the given base name, in the given directory
      Parameters:
      pStream - the InputStream to read from
      pTempBaseName - optional base name for the temporary file
      pTempDir - 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: Seekable
      Returns true if this 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.
      Specified by:
      isCachedMemory in interface Seekable
      Returns:
      true if this Seekable caches data in main memory.
      See Also:
    • isCachedFile

      public final boolean isCachedFile()
      Description copied from interface: Seekable
      Returns true if this 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.
      Specified by:
      isCachedFile in interface Seekable
      Returns:
      true if this Seekable caches data in a temporary file.
      See Also:
    • closeImpl

      protected void closeImpl() throws IOException
      Throws:
      IOException
    • read

      public int read() throws IOException
      Throws:
      IOException
    • read

      public int read(byte[] pBytes, int pOffset, int pLength) throws IOException
      Throws:
      IOException
    • getCache

      protected final com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache getCache()
    • available

      public int available() throws IOException
      Overrides:
      available in class InputStream
      Throws:
      IOException
    • syncPosition

      protected final void syncPosition() throws IOException
      Throws:
      IOException
    • isCached

      public final boolean isCached()
      Description copied from interface: Seekable
      Returns true if this 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.
      Returns:
      true if this Seekable caches data.
      See Also:
    • seekImpl

      protected void seekImpl(long pPosition) throws IOException
      Specified by:
      seekImpl in class SeekableInputStream
      Throws:
      IOException
    • flushBeforeImpl

      protected void flushBeforeImpl(long pPosition)
      Description copied from class: SeekableInputStream
      Discards the initial portion of the stream prior to the indicated postion.
      Specified by:
      flushBeforeImpl in class SeekableInputStream
      Parameters:
      pPosition - the position to flush to
      See Also: