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
-
Field Summary
-
Constructor Summary
Constructors Constructor Description FileCacheRandomAccessInputStream(java.io.InputStream stream)
Constructs aMemoryCacheRandomAccessInputStream
that takes its source data from a regularInputStream
.FileCacheRandomAccessInputStream(java.io.InputStream src, int bufLen)
-
Method Summary
Modifier and Type Method Description void
close()
Closes this stream and releases any system resources associated with the stream.long
getStreamPointer()
Returns the current offset in this stream.int
read()
int
read(byte[] b, int off, int len)
void
seek(long pos)
Sets the stream-pointer offset, measured from the beginning of this file, at which the next read occurs.void
shallowClose()
Closes the RandomAccessInputStream and it's underlying streamMethods inherited from class pixy.io.RandomAccessInputStream
ensureOpen, finalize, getEndian, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readS15Fixed16Number, readShort, readU16Fixed16Number, readU8Fixed8Number, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, setReadStrategy, skipBytes
-
Constructor Details
-
FileCacheRandomAccessInputStream
public FileCacheRandomAccessInputStream(java.io.InputStream stream) throws java.io.IOExceptionConstructs aMemoryCacheRandomAccessInputStream
that takes its source data from a regularInputStream
. 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 classRandomAccessInputStream
- 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.IOExceptionSets the stream-pointer offset, measured from the beginning of this file, at which the next read occurs.- Specified by:
seek
in classRandomAccessInputStream
- 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
- ifpos
is less than0
or if an I/O error occurs.
-
read
public int read() throws java.io.IOException- Specified by:
read
in classRandomAccessInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Specified by:
read
in classRandomAccessInputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses this stream and releases any system resources associated with the stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- if an I/O error occurs.
-
shallowClose
public void shallowClose() throws java.io.IOExceptionDescription copied from class:RandomAccessInputStream
Closes the RandomAccessInputStream and it's underlying stream- Specified by:
shallowClose
in classRandomAccessInputStream
- Throws:
java.io.IOException
-