public class BufferedDataInputStream extends java.io.BufferedInputStream implements ArrayDataInput
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. [This has subsequently happened with the NIO package and in an ideal universe these classes would be rewritten to take advantage of NIO.]
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. Version 1.2: July 20, 2009: Added handling of very large Object arrays. Additional work is required to handle very large arrays generally.
| Constructor and Description |
|---|
BufferedDataInputStream(java.io.InputStream o)
Use the BufferedInputStream constructor
|
BufferedDataInputStream(java.io.InputStream o,
int bufLength)
Use the BufferedInputStream constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected long |
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)
Deprecated.
See readLArray(Object) which handles large arrays properly.
|
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.
|
long |
readLArray(java.lang.Object o)
Read an object.
|
java.lang.String |
readLine()
Deprecated.
Use BufferedReader methods.
|
long |
readLong()
Read a long.
|
int |
readPrimitiveArray(java.lang.Object o)
Deprecated.
See readLArray(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) |
long |
skipBytes(long toSkip) |
java.lang.String |
toString()
Represent the stream as a string
|
available, close, mark, markSupported, read, reset, skipclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitclose, read, skippublic BufferedDataInputStream(java.io.InputStream o)
public BufferedDataInputStream(java.io.InputStream o,
int bufLength)
public int read(byte[] obuf,
int offset,
int len)
throws java.io.IOException
read in interface ArrayDataInputread in class java.io.BufferedInputStreamobuf - The byte array.offset - The starting offset into the array.len - The number of bytes to read.java.io.IOExceptionpublic boolean readBoolean()
throws java.io.IOException
readBoolean in interface java.io.DataInputjava.io.IOExceptionpublic byte readByte()
throws java.io.IOException
readByte in interface java.io.DataInputjava.io.IOExceptionpublic int readUnsignedByte()
throws java.io.IOException
readUnsignedByte in interface java.io.DataInputjava.io.IOExceptionpublic int readInt()
throws java.io.IOException
readInt in interface java.io.DataInputjava.io.IOExceptionpublic short readShort()
throws java.io.IOException
readShort in interface java.io.DataInputjava.io.IOExceptionpublic int readUnsignedShort()
throws java.io.IOException
readUnsignedShort in interface java.io.DataInputjava.io.IOExceptionpublic char readChar()
throws java.io.IOException
readChar in interface java.io.DataInputjava.io.IOExceptionpublic long readLong()
throws java.io.IOException
readLong in interface java.io.DataInputjava.io.IOExceptionpublic float readFloat()
throws java.io.IOException
readFloat in interface java.io.DataInputjava.io.IOExceptionpublic double readDouble()
throws java.io.IOException
readDouble in interface java.io.DataInputjava.io.IOExceptionpublic void readFully(byte[] b)
throws java.io.IOException
readFully in interface java.io.DataInputb - The buffer to be read.java.io.IOExceptionpublic void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
readFully in interface java.io.DataInputb - The input buffer.off - The requested offset into the buffer.len - The number of bytes requested.java.io.IOExceptionpublic int skipBytes(int toSkip)
throws java.io.IOException
skipBytes in interface java.io.DataInputjava.io.IOExceptionpublic long skipBytes(long toSkip)
throws java.io.IOException
skipBytes in interface ArrayDataInputjava.io.IOExceptionpublic java.lang.String readUTF()
throws java.io.IOException
readUTF in interface java.io.DataInputjava.io.IOExceptionpublic java.lang.String readLine()
throws java.io.IOException
readLine in interface java.io.DataInputjava.io.IOExceptionpublic 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.IOExceptionpublic int readArray(java.lang.Object o)
throws java.io.IOException
readArray in interface ArrayDataInputo - The object to be read. This object should
be a primitive (possibly multi-dimensional) array.java.io.IOExceptionpublic long readLArray(java.lang.Object o)
throws java.io.IOException
readLArray in interface ArrayDataInputo - The object to be read. This object should
be a primitive (possibly multi-dimensional) array.java.io.IOExceptionprotected long primitiveArrayRecurse(java.lang.Object o)
throws java.io.IOException
java.io.IOExceptionpublic int read(boolean[] b)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(boolean[] b,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(short[] s)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(short[] s,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(char[] c)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(char[] c,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(int[] i)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(int[] i,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(long[] l)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(long[] l,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(float[] f)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(float[] f,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(double[] d)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic int read(double[] d,
int start,
int len)
throws java.io.IOException
read in interface ArrayDataInputjava.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object