Class FileCacheSeekableStream

  • All Implemented Interfaces:
    Seekable, java.io.Closeable, java.lang.AutoCloseable

    public final class FileCacheSeekableStream
    extends AbstractCachedSeekableStream
    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:
    MemoryCacheSeekableStream, FileSeekableStream, File.createTempFile(String, String), RandomAccessFile
    • Field Detail

      • buffer

        private byte[] buffer
    • Constructor Detail

      • FileCacheSeekableStream

        public FileCacheSeekableStream​(java.io.InputStream pStream)
                                throws java.io.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:
        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 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:
        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 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:
        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 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
        Specified by:
        isCachedMemory in class AbstractCachedSeekableStream
        Returns:
        true if this Seekable caches data in main memory.
        See Also:
        Seekable.isCached(), Seekable.isCachedFile()
      • 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
        Specified by:
        isCachedFile in class AbstractCachedSeekableStream
        Returns:
        true if this Seekable caches data in a temporary file.
        See Also:
        Seekable.isCached(), Seekable.isCachedMemory()
      • read

        public int read​(byte[] pBytes,
                        int pOffset,
                        int pLength)
                 throws java.io.IOException
        Overrides:
        read in class AbstractCachedSeekableStream
        Throws:
        java.io.IOException
      • readAhead

        private int readAhead​(byte[] pBytes,
                              int pOffset,
                              int pLength)
                       throws java.io.IOException
        Throws:
        java.io.IOException