|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
loci.formats.RandomAccessStream
public class RandomAccessStream
RandomAccessStream provides methods for "intelligent" reading of files and byte arrays. It also automagically deals with closing and reopening files to prevent an IOException caused by too many open files.
Field Summary | |
---|---|
protected long |
afp
The "absolute" file pointer. |
protected static int |
ARRAY
|
protected byte[] |
buf
Starting buffer. |
protected boolean |
compressed
Flag indicating this file has been compressed. |
protected DataInputStream |
dis
|
protected static int |
DIS
Indicators for most efficient method of reading. |
protected int |
ext
Number of bytes by which to extend the stream. |
protected String |
file
The file name. |
protected long |
fp
The file pointer within the DIS. |
protected int |
lastValid
Number of valid entries in the buffer size array. |
protected long |
length
Length of the file. |
protected boolean |
littleEndian
Endianness of the stream. |
protected long |
mark
Most recent mark. |
protected static int |
MAX_FILES
Maximum number of open files. |
protected static int |
MAX_HISTORY
Maximum number of buffer sizes to keep. |
protected static int |
MAX_OVERHEAD
Maximum size of the buffer used by the DataInputStream. |
protected long |
nextMark
Next place to mark. |
protected IRandomAccess |
raf
|
protected static int |
RAF
|
Constructor Summary | |
---|---|
RandomAccessStream(byte[] array)
Constructs a random access stream around the given byte array. |
|
RandomAccessStream(String file)
Constructs a hybrid RandomAccessFile/DataInputStream around the given file. |
Method Summary | |
---|---|
int |
available()
|
protected int |
checkEfficiency(int toRead)
Determine whether it is more efficient to use the DataInputStream or RandomAccessFile for reading (based on the current file pointers). |
void |
close()
Closes the streams. |
protected int |
determineBuffer()
Naive heuristic for determining a "good" buffer size for the DIS. |
long |
getFilePointer()
Gets the current (absolute) file pointer. |
DataInputStream |
getInputStream()
Returns the underlying InputStream. |
boolean |
isLittleEndian()
Gets the endianness of the stream. |
long |
length()
Gets the number of bytes in the file. |
void |
mark(int readLimit)
|
boolean |
markSupported()
|
void |
order(boolean little)
Sets the endianness of the stream. |
int |
read()
Alias for readByte(). |
int |
read(byte[] array)
Read bytes from the stream into the given array. |
int |
read(byte[] array,
int offset,
int n)
Read n bytes from the stream into the given array at the specified offset. |
boolean |
readBoolean()
Read an input byte and return true if the byte is nonzero. |
byte |
readByte()
Read one byte and return it. |
char |
readChar()
Read an input char. |
double |
readDouble()
Read eight bytes and return a double value. |
float |
readFloat()
Read four bytes and return a float value. |
void |
readFully(byte[] array)
Read bytes from the stream into the given array. |
void |
readFully(byte[] array,
int offset,
int n)
Read n bytes from the stream into the given array at the specified offset. |
int |
readInt()
Read four input bytes and return an int value. |
String |
readLine()
Read the next line of text from the input stream. |
long |
readLong()
Read eight input bytes and return a long value. |
short |
readShort()
Read two input bytes and return a short value. |
String |
readString(int n)
Read a string of length n. |
int |
readUnsignedByte()
Read an input byte and zero extend it appropriately. |
int |
readUnsignedShort()
Read two bytes and return an int in the range 0 through 65535. |
String |
readUTF()
Read a string that has been encoded using a modified UTF-8 format. |
void |
reset()
|
void |
seek(long pos)
Seeks to the given offset within the stream. |
void |
setExtend(int extend)
Sets the number of bytes by which to extend the stream. |
int |
skipBytes(int n)
Skip n bytes within the stream. |
Methods inherited from class java.io.InputStream |
---|
skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int MAX_OVERHEAD
protected static final int MAX_HISTORY
protected static final int MAX_FILES
protected static final int DIS
protected static final int RAF
protected static final int ARRAY
protected IRandomAccess raf
protected DataInputStream dis
protected long length
protected long fp
protected long afp
protected long mark
protected long nextMark
protected String file
protected byte[] buf
protected boolean littleEndian
protected int ext
protected int lastValid
protected boolean compressed
Constructor Detail |
---|
public RandomAccessStream(String file) throws IOException
IOException
public RandomAccessStream(byte[] array) throws IOException
IOException
Method Detail |
---|
public DataInputStream getInputStream()
public void setExtend(int extend)
public void seek(long pos) throws IOException
IOException
public int read() throws IOException
read
in class InputStream
IOException
public long length() throws IOException
IOException
public long getFilePointer()
public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
public void order(boolean little)
public boolean isLittleEndian()
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
public String readString(int n) throws IOException
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
public int read(byte[] array) throws IOException
read
in class InputStream
IOException
public int read(byte[] array, int offset, int n) throws IOException
read
in class InputStream
IOException
public void readFully(byte[] array) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] array, int offset, int n) throws IOException
readFully
in interface DataInput
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void mark(int readLimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public void reset() throws IOException
reset
in class InputStream
IOException
protected int determineBuffer()
protected int checkEfficiency(int toRead) throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |