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 protected
RandomAccessInputStream(java.io.InputStream src)
-
Method Summary
Modifier and Type Method Description protected void
ensureOpen()
Check to make sure that this stream has not been closedprotected void
finalize()
short
getEndian()
abstract long
getStreamPointer()
abstract int
read()
abstract int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
java.lang.String
readLine()
Deprecated.long
readLong()
float
readS15Fixed16Number()
short
readShort()
float
readU16Fixed16Number()
float
readU8Fixed8Number()
int
readUnsignedByte()
long
readUnsignedInt()
int
readUnsignedShort()
java.lang.String
readUTF()
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 void
seek(long loc)
void
setReadStrategy(ReadStrategy strategy)
abstract void
shallowClose()
Closes the RandomAccessInputStream and it's underlying streamint
skipBytes(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:
finalize
in 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:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public abstract int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
readBoolean
public final boolean readBoolean() throws java.io.IOException- Specified by:
readBoolean
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readByte
public final byte readByte() throws java.io.IOException- Specified by:
readByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readChar
public final char readChar() throws java.io.IOException- Specified by:
readChar
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readDouble
public final double readDouble() throws java.io.IOException- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFloat
public final float readFloat() throws java.io.IOException- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public final void readFully(byte[] b) throws java.io.IOException- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public final void readFully(byte[] b, int off, int len) throws java.io.IOException- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readInt
public final int readInt() throws java.io.IOException- Specified by:
readInt
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLine
@Deprecated public final java.lang.String readLine() throws java.io.IOExceptionDeprecated.- Specified by:
readLine
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLong
public final long readLong() throws java.io.IOException- Specified by:
readLong
in 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:
readShort
in 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:
readUnsignedByte
in 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:
readUnsignedShort
in 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:
readUTF
in 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:
skipBytes
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-