Class MemoryCacheSeekableStream.MemoryCache

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int BLOCK_SIZE  
      private java.util.List<byte[]> cache  
      private long length  
      private long position  
      private long start  
    • Constructor Summary

      Constructors 
      Constructor Description
      MemoryCache()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void close()  
      void flush​(long pPosition)
      Optionally flushes any data prior to the given position.
      private byte[] getBlock()  
      long getPosition()
      Returns the current cache read/write position.
      int read()
      Reads a single byte a the current read/write position.
      int read​(byte[] pBytes, int pOffset, int pLength)
      Writes a series of bytes at the current read/write position.
      void seek​(long pPosition)
      Repositions the current cache read/write position to the given position.
      void write​(byte[] pBuffer, int pOffset, int pLength)
      Writes a series of bytes at the current read/write position.
      void write​(int pByte)
      Writes a single byte at the current read/write position.
      • Methods inherited from class java.lang.Object

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

      • cache

        private final java.util.List<byte[]> cache
      • length

        private long length
      • position

        private long position
      • start

        private long start
    • Constructor Detail

      • MemoryCache

        MemoryCache()
    • Method Detail

      • getBlock

        private byte[] getBlock()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public void write​(int pByte)
                   throws java.io.IOException
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Writes a single byte at the current read/write position. The read/write position will be increased by one.
        Specified by:
        write in class AbstractCachedSeekableStream.StreamCache
        Parameters:
        pByte - the byte value to write.
        Throws:
        java.io.IOException - if an I/O exception occurs in the cache backing mechanism.
      • write

        public void write​(byte[] pBuffer,
                          int pOffset,
                          int pLength)
                   throws java.io.IOException
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Writes a series of bytes at the current read/write position. The read/write position will be increased by pLength.

        This implementation invokes AbstractCachedSeekableStream.StreamCache.write(int) pLength times. Subclasses may override this method for performance.

        Overrides:
        write in class AbstractCachedSeekableStream.StreamCache
        Parameters:
        pBuffer - the bytes to write.
        pOffset - the starting offset into the buffer.
        pLength - the number of bytes to write from the buffer.
        Throws:
        java.io.IOException - if an I/O exception occurs in the cache backing mechanism.
      • read

        public int read()
                 throws java.io.IOException
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Reads a single byte a the current read/write position. The read/write position will be increased by one.
        Specified by:
        read in class AbstractCachedSeekableStream.StreamCache
        Returns:
        the value read, or -1 to indicate EOF.
        Throws:
        java.io.IOException - if an I/O exception occurs in the cache backing mechanism.
      • read

        public int read​(byte[] pBytes,
                        int pOffset,
                        int pLength)
                 throws java.io.IOException
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Writes a series of bytes at the current read/write position. The read/write position will be increased by pLength.

        This implementation invokes AbstractCachedSeekableStream.StreamCache.read() pLength times. Subclasses may override this method for performance.

        Overrides:
        read in class AbstractCachedSeekableStream.StreamCache
        Parameters:
        pBytes - the bytes to write
        pOffset - the starting offset into the buffer.
        pLength - the number of bytes to write from the buffer.
        Returns:
        the number of bytes read, or -1 to indicate EOF.
        Throws:
        java.io.IOException - if an I/O exception occurs in the cache backing mechanism.
      • seek

        public void seek​(long pPosition)
                  throws java.io.IOException
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Repositions the current cache read/write position to the given position.
        Specified by:
        seek in class AbstractCachedSeekableStream.StreamCache
        Parameters:
        pPosition - the new read/write position
        Throws:
        java.io.IOException - if an I/O exception occurs in the cache backing mechanism.
      • flush

        public void flush​(long pPosition)
        Description copied from class: AbstractCachedSeekableStream.StreamCache
        Optionally flushes any data prior to the given position.

        Attempting to perform a seek operation, and/or a read or write operation to a position equal to or before the flushed position may result in exceptions or undefined behaviour.

        Subclasses should override this method for performance reasons, to avoid holding on to unnecessary resources. This implementation does nothing.

        Overrides:
        flush in class AbstractCachedSeekableStream.StreamCache
        Parameters:
        pPosition - the last position to flush.