Package pixy.io

Class FileCacheRandomAccessInputStream

java.lang.Object
java.io.InputStream
pixy.io.RandomAccessInputStream
pixy.io.FileCacheRandomAccessInputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable

public class FileCacheRandomAccessInputStream
extends RandomAccessInputStream
Implements a file cached random access input stream to ease the decoding of some types of images such as TIFF which may need random access to the underlying stream.

Based on com.sun.media.jai.codec.FileCacheSeekableStream.

Version:
1.0 02/09/2014
Author:
Wen Yu, yuwen_66@yahoo.com
  • Constructor Details

    • FileCacheRandomAccessInputStream

      public FileCacheRandomAccessInputStream​(java.io.InputStream stream) throws java.io.IOException
      Constructs a MemoryCacheRandomAccessInputStream that takes its source data from a regular InputStream. Seeking backwards is supported by means of an file cache.

      An IOException will be thrown if the attempt to create the cache file fails for any reason.

      Throws:
      java.io.IOException
    • FileCacheRandomAccessInputStream

      public FileCacheRandomAccessInputStream​(java.io.InputStream src, int bufLen) throws java.io.IOException
      Throws:
      java.io.IOException
  • Method Details

    • getStreamPointer

      public long getStreamPointer()
      Returns the current offset in this stream.
      Specified by:
      getStreamPointer in class RandomAccessInputStream
      Returns:
      the offset from the beginning of the stream, in bytes, at which the next read occurs.
    • seek

      public void seek​(long pos) throws java.io.IOException
      Sets the stream-pointer offset, measured from the beginning of this file, at which the next read occurs.
      Specified by:
      seek in class RandomAccessInputStream
      Parameters:
      pos - the offset position, measured in bytes from the beginning of the stream, at which to set the stream pointer.
      Throws:
      java.io.IOException - if pos is less than 0 or if an I/O error occurs.
    • read

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

      public int read​(byte[] b, int off, int len) throws java.io.IOException
      Specified by:
      read in class RandomAccessInputStream
      Throws:
      java.io.IOException
    • close

      public void close() throws java.io.IOException
      Closes this stream and releases any system resources associated with the stream.
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Overrides:
      close in class java.io.InputStream
      Throws:
      java.io.IOException - if an I/O error occurs.
    • shallowClose

      public void shallowClose() throws java.io.IOException
      Description copied from class: RandomAccessInputStream
      Closes the RandomAccessInputStream and it's underlying stream
      Specified by:
      shallowClose in class RandomAccessInputStream
      Throws:
      java.io.IOException