Class FileCache

  • All Implemented Interfaces:
    Cache, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.SeekableByteChannel, java.nio.channels.WritableByteChannel

    final class FileCache
    extends java.lang.Object
    implements Cache
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int BLOCK_SIZE  
      private java.nio.channels.FileChannel cache  
      private java.nio.channels.ReadableByteChannel channel  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileCache​(java.io.InputStream stream, java.io.File cacheDir)  
      FileCache​(java.nio.channels.ReadableByteChannel channel, java.io.File cacheDir)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      (package private) void fetch()  
      void flushBefore​(long pos)  
      boolean isOpen()  
      long position()  
      java.nio.channels.SeekableByteChannel position​(long newPosition)  
      int read​(java.nio.ByteBuffer dest)  
      long size()  
      java.nio.channels.SeekableByteChannel truncate​(long size)  
      int write​(java.nio.ByteBuffer src)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cache

        private final java.nio.channels.FileChannel cache
      • channel

        private final java.nio.channels.ReadableByteChannel channel
    • Constructor Detail

      • FileCache

        FileCache​(java.io.InputStream stream,
                  java.io.File cacheDir)
           throws java.io.IOException
        Throws:
        java.io.IOException
      • FileCache

        public FileCache​(java.nio.channels.ReadableByteChannel channel,
                         java.io.File cacheDir)
                  throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • fetch

        void fetch()
            throws java.io.IOException
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dest)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Specified by:
        read in interface java.nio.channels.SeekableByteChannel
        Throws:
        java.io.IOException
      • position

        public long position()
                      throws java.io.IOException
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
        Throws:
        java.io.IOException
      • position

        public java.nio.channels.SeekableByteChannel position​(long newPosition)
                                                       throws java.io.IOException
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
        Throws:
        java.io.IOException
      • size

        public long size()
        Specified by:
        size in interface java.nio.channels.SeekableByteChannel
      • write

        public int write​(java.nio.ByteBuffer src)
        Specified by:
        write in interface java.nio.channels.SeekableByteChannel
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
      • truncate

        public java.nio.channels.SeekableByteChannel truncate​(long size)
        Specified by:
        truncate in interface java.nio.channels.SeekableByteChannel
      • flushBefore

        public void flushBefore​(long pos)
        Specified by:
        flushBefore in interface Cache