Class AbstractCachedSeekableStream.StreamCache

java.lang.Object
com.twelvemonkeys.io.AbstractCachedSeekableStream.StreamCache
Direct Known Subclasses:
FileCacheSeekableStream.FileCache, MemoryCacheSeekableStream.MemoryCache
Enclosing class:
AbstractCachedSeekableStream

abstract static class AbstractCachedSeekableStream.StreamCache extends Object
An abstract stream cache.
Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/AbstractCachedSeekableStream.java#2 $
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a StreamCache.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) abstract void
     
    (package private) void
    flush(long pPosition)
    Optionally flushes any data prior to the given position.
    (package private) abstract long
    Returns the current cache read/write position.
    (package private) abstract int
    Reads a single byte a the current read/write position.
    (package private) int
    read(byte[] pBuffer, int pOffset, int pLength)
    Writes a series of bytes at the current read/write position.
    (package private) abstract void
    seek(long pPosition)
    Repositions the current cache read/write position to the given position.
    (package private) void
    write(byte[] pBuffer, int pOffset, int pLength)
    Writes a series of bytes at the current read/write position.
    (package private) abstract 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
  • Constructor Details

    • StreamCache

      StreamCache()
      Creates a StreamCache.
  • Method Details

    • write

      abstract void write(int pByte) throws IOException
      Writes a single byte at the current read/write position. The read/write position will be increased by one.
      Parameters:
      pByte - the byte value to write.
      Throws:
      IOException - if an I/O exception occurs in the cache backing mechanism.
    • write

      void write(byte[] pBuffer, int pOffset, int pLength) throws IOException
      Writes a series of bytes at the current read/write position. The read/write position will be increased by pLength.

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

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

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

      int read(byte[] pBuffer, int pOffset, int pLength) throws IOException
      Writes a series of bytes at the current read/write position. The read/write position will be increased by pLength.

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

      Parameters:
      pBuffer - 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:
      IOException - if an I/O exception occurs in the cache backing mechanism.
    • seek

      abstract void seek(long pPosition) throws IOException
      Repositions the current cache read/write position to the given position.
      Parameters:
      pPosition - the new read/write position
      Throws:
      IOException - if an I/O exception occurs in the cache backing mechanism.
    • flush

      void flush(long pPosition)
      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.

      Parameters:
      pPosition - the last position to flush.
    • getPosition

      abstract long getPosition() throws IOException
      Returns the current cache read/write position.
      Returns:
      the current cache read/write postion.
      Throws:
      IOException - if the position can't be determined because of a problem in the cache backing mechanism.
    • close

      abstract void close() throws IOException
      Throws:
      IOException