|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
nom.tam.util.BufferedDataInputStream
public class BufferedDataInputStream
This class is intended for high performance I/O in scientific applications. It combines the functionality of the BufferedInputStream and the DataInputStream as well as more efficient handling of arrays. This minimizes the number of method calls that are required to read data. Informal tests of this method show that it can be as much as 10 times faster than using a DataInputStream layered on a BufferedInputStream for writing large arrays. The performance gain on scalars or small arrays will be less but there should probably never be substantial degradation of performance.
Many new read calls are added to allow efficient reading off array data. The read(Object o) call provides for reading a primitive array of arbitrary type or dimensionality. There are also reads for each type of one dimensional array.
Note that there is substantial duplication of code to minimize method invocations. E.g., the floating point read routines read the data as integer values and then convert to float. However the integer code is duplicated rather than invoked. There has been considerable effort expended to ensure that these routines are efficient, but they could easily be superceded if an efficient underlying I/O package were ever delivered as part of the basic Java libraries.
Testing and timing routines are provided in the nom.tam.util.test.BufferedFileTester class. Version 1.1: October 12, 2000: Fixed handling of EOF to return partially read arrays when EOF is detected.
Field Summary |
---|
Fields inherited from class java.io.BufferedInputStream |
---|
buf, count, marklimit, markpos, pos |
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
BufferedDataInputStream(java.io.InputStream o)
Use the BufferedInputStream constructor |
|
BufferedDataInputStream(java.io.InputStream o,
int bufLength)
Use the BufferedInputStream constructor |
Method Summary | |
---|---|
protected int |
primitiveArrayRecurse(java.lang.Object o)
Read recursively over a multi-dimensional array. |
int |
read(boolean[] b)
Read a boolean array |
int |
read(boolean[] b,
int start,
int len)
Read a boolean array. |
int |
read(byte[] obuf,
int offset,
int len)
Read a byte array. |
int |
read(char[] c)
Read a character array |
int |
read(char[] c,
int start,
int len)
Read a character array |
int |
read(double[] d)
Read a double array |
int |
read(double[] d,
int start,
int len)
Read a double array |
int |
read(float[] f)
Read a float array |
int |
read(float[] f,
int start,
int len)
Read a float array |
int |
read(int[] i)
Read an integer array |
int |
read(int[] i,
int start,
int len)
Read an integer array |
int |
read(long[] l)
Read a long array |
int |
read(long[] l,
int start,
int len)
Read a long array |
int |
read(short[] s)
Read a short array |
int |
read(short[] s,
int start,
int len)
Read a short array |
int |
readArray(java.lang.Object o)
Read an object. |
boolean |
readBoolean()
Read a boolean value. |
byte |
readByte()
Read a byte value in the range -128 to 127. |
char |
readChar()
Read a 2-byte value as a character. |
double |
readDouble()
Read an 8 byte real number. |
float |
readFloat()
Read a 4 byte real number. |
void |
readFully(byte[] b)
Read a buffer and signal an EOF if the buffer cannot be fully read. |
void |
readFully(byte[] b,
int off,
int len)
Read a buffer and signal an EOF if the requested elements cannot be read. |
int |
readInt()
Read an integer. |
java.lang.String |
readLine()
Deprecated. Use BufferedReader methods. |
long |
readLong()
Read a long. |
int |
readPrimitiveArray(java.lang.Object o)
Deprecated. See readArray(Object o). |
short |
readShort()
Read a 2-byte value as a short (-32788 to 32767) |
int |
readUnsignedByte()
Read a byte value in the range 0-255. |
int |
readUnsignedShort()
Read a 2-byte value in the range 0-65536. |
java.lang.String |
readUTF()
Read a String in the UTF format. |
int |
skipBytes(int toSkip)
Skip the requested number of bytes. |
java.lang.String |
toString()
Represent the stream as a string |
Methods inherited from class java.io.BufferedInputStream |
---|
available, close, mark, markSupported, read, reset, skip |
Methods inherited from class java.io.FilterInputStream |
---|
read |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface nom.tam.util.ArrayDataInput |
---|
close, read, skip |
Constructor Detail |
---|
public BufferedDataInputStream(java.io.InputStream o)
public BufferedDataInputStream(java.io.InputStream o, int bufLength)
Method Detail |
---|
public int read(byte[] obuf, int offset, int len) throws java.io.IOException
read
in interface ArrayDataInput
read
in class java.io.BufferedInputStream
obuf
- The byte array.offset
- The starting offset into the array.len
- The number of bytes to read.
java.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
readFully
in interface java.io.DataInput
b
- The buffer to be read.
java.io.IOException
public void readFully(byte[] b, int off, int len) throws java.io.IOException
readFully
in interface java.io.DataInput
b
- The input buffer.off
- The requested offset into the buffer.len
- The number of bytes requested.
java.io.IOException
public int skipBytes(int toSkip) throws java.io.IOException
skipBytes
in interface java.io.DataInput
toSkip
- The number of bytes to skip.
java.io.IOException
public java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public int readPrimitiveArray(java.lang.Object o) throws java.io.IOException
o
- The object to be read. It must be an array of a primitive type,
or an array of Object's.
java.io.IOException
public int readArray(java.lang.Object o) throws java.io.IOException
readArray
in interface ArrayDataInput
o
- The object to be read. This object should
be a primitive (possibly multi-dimensional) array.
java.io.IOException
protected int primitiveArrayRecurse(java.lang.Object o) throws java.io.IOException
java.io.IOException
public int read(boolean[] b) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(boolean[] b, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(short[] s) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(short[] s, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(char[] c) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(char[] c, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(int[] i) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(int[] i, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(long[] l) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(long[] l, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(float[] f) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(float[] f, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(double[] d) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public int read(double[] d, int start, int len) throws java.io.IOException
read
in interface ArrayDataInput
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |