Package pixy.io
Class RandomAccessInputStream
java.lang.Object
java.io.InputStream
pixy.io.RandomAccessInputStream
- All Implemented Interfaces:
java.io.Closeable,java.io.DataInput,java.lang.AutoCloseable
- Direct Known Subclasses:
FileCacheRandomAccessInputStream,MemoryCacheRandomAccessInputStream
public abstract class RandomAccessInputStream
extends java.io.InputStream
implements java.io.DataInput
Implements a random access input stream
Based on com.sun.media.jai.codec.SeekableStream.
To make it flexible, this class and any of its sub-class doesn't close the underlying stream. It's up to the underlying stream creator to close them. This ensures the actual stream out-lives the random stream itself in case we need to read more content from the underlying stream.
NOTE: for MemoryCacheRandomAccessInputStream, there is the risk of "over read" in which more bytes are cached in the buffer than actually needed. In this case, the underlying stream might not be usable anymore afterwards.
- Version:
- 1.0 01/24/2013
- Author:
- Wen Yu, yuwen_66@yahoo.com
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedRandomAccessInputStream(java.io.InputStream src) -
Method Summary
Modifier and Type Method Description protected voidensureOpen()Check to make sure that this stream has not been closedprotected voidfinalize()shortgetEndian()abstract longgetStreamPointer()abstract intread()abstract intread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()java.lang.StringreadLine()Deprecated.longreadLong()floatreadS15Fixed16Number()shortreadShort()floatreadU16Fixed16Number()floatreadU8Fixed8Number()intreadUnsignedByte()longreadUnsignedInt()intreadUnsignedShort()java.lang.StringreadUTF()Due to the current implementation, writeUTF and readUTF are the only methods which are machine or byte sequence independent as they are actually both Motorola byte sequence under the hood.abstract voidseek(long loc)voidsetReadStrategy(ReadStrategy strategy)abstract voidshallowClose()Closes the RandomAccessInputStream and it's underlying streamintskipBytes(int n)
-
Field Details
-
Constructor Details
-
RandomAccessInputStream
protected RandomAccessInputStream(java.io.InputStream src)
-
-
Method Details
-
shallowClose
public abstract void shallowClose() throws java.io.IOExceptionCloses the RandomAccessInputStream and it's underlying stream- Throws:
java.io.IOException
-
ensureOpen
protected void ensureOpen() throws java.io.IOExceptionCheck to make sure that this stream has not been closed- Throws:
java.io.IOException
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
getEndian
public short getEndian() -
getStreamPointer
public abstract long getStreamPointer() -
read
public abstract int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public abstract int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
readBoolean
public final boolean readBoolean() throws java.io.IOException- Specified by:
readBooleanin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readByte
public final byte readByte() throws java.io.IOException- Specified by:
readBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readChar
public final char readChar() throws java.io.IOException- Specified by:
readCharin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readDouble
public final double readDouble() throws java.io.IOException- Specified by:
readDoublein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFloat
public final float readFloat() throws java.io.IOException- Specified by:
readFloatin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public final void readFully(byte[] b) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public final void readFully(byte[] b, int off, int len) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readInt
public final int readInt() throws java.io.IOException- Specified by:
readIntin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLine
@Deprecated public final java.lang.String readLine() throws java.io.IOExceptionDeprecated.- Specified by:
readLinein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLong
public final long readLong() throws java.io.IOException- Specified by:
readLongin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readS15Fixed16Number
public final float readS15Fixed16Number() throws java.io.IOException- Throws:
java.io.IOException
-
readShort
public final short readShort() throws java.io.IOException- Specified by:
readShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readU16Fixed16Number
public final float readU16Fixed16Number() throws java.io.IOException- Throws:
java.io.IOException
-
readU8Fixed8Number
public final float readU8Fixed8Number() throws java.io.IOException- Throws:
java.io.IOException
-
readUnsignedByte
public final int readUnsignedByte() throws java.io.IOException- Specified by:
readUnsignedBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedInt
public final long readUnsignedInt() throws java.io.IOException- Throws:
java.io.IOException
-
readUnsignedShort
public final int readUnsignedShort() throws java.io.IOException- Specified by:
readUnsignedShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUTF
public final java.lang.String readUTF() throws java.io.IOExceptionDue to the current implementation, writeUTF and readUTF are the only methods which are machine or byte sequence independent as they are actually both Motorola byte sequence under the hood. Whereas the following static method is byte sequence dependent as it calls readUnsignedShort of RandomAccessInputStream.DataInputStream.readUTF(this);- Specified by:
readUTFin interfacejava.io.DataInput- Throws:
java.io.IOException
-
seek
public abstract void seek(long loc) throws java.io.IOException- Throws:
java.io.IOException
-
setReadStrategy
-
skipBytes
public int skipBytes(int n) throws java.io.IOException- Specified by:
skipBytesin interfacejava.io.DataInput- Throws:
java.io.IOException
-