com.twelvemonkeys.io
Class MemoryCacheSeekableStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.twelvemonkeys.io.SeekableInputStream
          extended by com.twelvemonkeys.io.MemoryCacheSeekableStream
All Implemented Interfaces:
Seekable, java.io.Closeable

public final class MemoryCacheSeekableStream
extends SeekableInputStream

A SeekableInputStream implementation that caches data in memory.

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/MemoryCacheSeekableStream.java#3 $
Author:
Harald Kuhr
See Also:
FileCacheSeekableStream

Nested Class Summary
static class AbstractCachedSeekableStream.StreamCache
          An abstract stream cache.
 
Field Summary
protected  java.io.InputStream stream
          The backing stream
protected  long streamPosition
          The stream positon in the backing stream (stream)
 
Fields inherited from class com.twelvemonkeys.io.SeekableInputStream
markedPositions
 
Constructor Summary
MemoryCacheSeekableStream(java.io.InputStream pStream)
          Creates a MemoryCacheSeekableStream, reading from the given InputStream.
 
Method Summary
 int available()
           
protected  void closeImpl()
           
protected  void flushBeforeImpl(long pPosition)
          Discards the initial portion of the stream prior to the indicated postion.
protected  AbstractCachedSeekableStream.StreamCache getCache()
           
 boolean isCached()
          Returns true if this Seekable stream caches data itself in order to allow seeking backwards.
 boolean isCachedFile()
          Returns true if this Seekable stream caches data itself in order to allow seeking backwards, and the cache is kept in a temporary file.
 boolean isCachedMemory()
          Returns true if this Seekable stream caches data itself in order to allow seeking backwards, and the cache is kept in main memory.
 int read()
           
 int read(byte[] pBytes, int pOffset, int pLength)
           
protected  void seekImpl(long pPosition)
           
protected  void syncPosition()
           
 
Methods inherited from class com.twelvemonkeys.io.SeekableInputStream
checkOpen, close, finalize, flush, flushBefore, getFlushedPosition, getStreamPosition, mark, mark, markSupported, read, reset, seek, skip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stream

protected final java.io.InputStream stream
The backing stream


streamPosition

protected long streamPosition
The stream positon in the backing stream (stream)

Constructor Detail

MemoryCacheSeekableStream

public MemoryCacheSeekableStream(java.io.InputStream pStream)
Creates a MemoryCacheSeekableStream, reading from the given InputStream. Data will be cached in memory.

Parameters:
pStream - the InputStream to read from.
Method Detail

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:
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
Returns:
true if this Seekable caches data in a temporary file.
See Also:
Seekable.isCached(), Seekable.isCachedMemory()

getCache

protected final AbstractCachedSeekableStream.StreamCache getCache()

available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

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

syncPosition

protected final void syncPosition()
                           throws java.io.IOException
Throws:
java.io.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:
Seekable.isCachedMemory(), Seekable.isCachedFile()

seekImpl

protected void seekImpl(long pPosition)
                 throws java.io.IOException
Specified by:
seekImpl in class SeekableInputStream
Throws:
java.io.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:
SeekableInputStream.flushBefore(long)

closeImpl

protected void closeImpl()
                  throws java.io.IOException
Specified by:
closeImpl in class SeekableInputStream
Throws:
java.io.IOException


Copyright © 2014. All Rights Reserved.