public class BufferedDataInputStream extends 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.
in
BITS_OF_1_BYTE, BITS_OF_2_BYTES, BITS_OF_3_BYTES, BITS_OF_4_BYTES, BITS_OF_5_BYTES, BITS_OF_6_BYTES, BITS_OF_7_BYTES, BYTE_1_OF_LONG_MASK, BYTE_2_OF_LONG_MASK, BYTE_3_OF_LONG_MASK, BYTE_4_OF_LONG_MASK, BYTE_MASK, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_FLOAT, BYTES_IN_INTEGER, BYTES_IN_LONG, BYTES_IN_SHORT, DEFAULT_BUFFER_SIZE, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASK
Constructor and Description |
---|
BufferedDataInputStream(InputStream o)
Create a BufferedInputStream based on an input stream.
|
BufferedDataInputStream(InputStream o,
int bufLength)
Create a BufferedInputStream based on a input stream with a specified
buffer size.
|
Modifier and Type | Method and Description |
---|---|
int |
read(boolean[] b)
Read an array of boolean's.
|
int |
read(boolean[] b,
int start,
int length)
Read a segment of an array of boolean's.
|
int |
read(byte[] obuf,
int offset,
int length)
Read a segment of an array of byte's.
|
int |
read(char[] c)
Read an array of char's.
|
int |
read(char[] c,
int start,
int length)
Read a segment of an array of char's.
|
int |
read(double[] d)
Read an array of double's.
|
int |
read(double[] d,
int start,
int length)
Read a segment of an array of double's.
|
int |
read(float[] f)
Read an array of float's.
|
int |
read(float[] f,
int start,
int length)
Read a segment of an array of float's.
|
int |
read(int[] i)
Read an array of int's.
|
int |
read(int[] i,
int start,
int length)
Read a segment of an array of int's.
|
int |
read(long[] l)
Read a segment of an array of long's.
|
int |
read(long[] l,
int start,
int length)
Read a segment of an array of long's.
|
int |
read(short[] s)
Read an array of short's.
|
int |
read(short[] s,
int start,
int length)
Read a segment of an array of short's.
|
int |
readArray(Object o)
Deprecated.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len)
Read a buffer and signal an EOF if the requested elements cannot be read.
|
int |
readInt() |
long |
readLArray(Object o)
Read an object.
|
String |
readLine()
Deprecated.
Use
BufferedReader methods. |
long |
readLong() |
int |
readPrimitiveArray(Object o)
Deprecated.
use
readLArray(Object) instead |
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
skipAllBytes(int toSkip)
Skip the number of bytes.
|
void |
skipAllBytes(long toSkip)
Skip the number of bytes.
|
int |
skipBytes(int toSkip) |
String |
toString() |
available, close, mark, markSupported, read, reset, skip
read
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
mark, read, reset, skip
public BufferedDataInputStream(InputStream o)
o
- the input stream to use for reading.public BufferedDataInputStream(InputStream o, int bufLength)
o
- the input stream to use for reading.bufLength
- the buffer length to use.public int read(boolean[] b) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
b
- array of boolean's.IOException
- if one of the underlying read operations failedpublic int read(boolean[] b, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
b
- array of boolean's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(byte[] obuf, int offset, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
read
in class BufferedInputStream
obuf
- array of byte's.offset
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedArrayDataInput.readFully(byte[], int, int)
public int read(char[] c) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
c
- array of char's.IOException
- if one of the underlying read operations failedpublic int read(char[] c, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
c
- array of char's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(double[] d) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
d
- array of double's.IOException
- if one of the underlying read operations failedpublic int read(double[] d, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
d
- array of double's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(float[] f) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
f
- array of float's.IOException
- if one of the underlying read operations failedpublic int read(float[] f, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
f
- array of float's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(int[] i) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
i
- array of int's.IOException
- if one of the underlying read operations failedpublic int read(int[] i, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
i
- array of int's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(long[] l) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
l
- array of long's.IOException
- if one of the underlying read operations failedpublic int read(long[] l, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
l
- array of long's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failedpublic int read(short[] s) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
s
- array of short's.IOException
- if one of the underlying read operations failedpublic int read(short[] s, int start, int length) throws IOException
ArrayDataInput
read
in interface ArrayDataInput
s
- array of short's.start
- start index in the arraylength
- number of array elements to readIOException
- if one of the underlying read operations failed@Deprecated public int readArray(Object o) throws IOException
ArrayDataInput
The ArrayDataInput classes do not support String input since it is unclear how one would read in an Array of strings.
readArray
in interface ArrayDataInput
o
- A [multidimensional] primitive (or Object) array.IOException
- if the underlying stream failedpublic 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 void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
ArrayDataInput
readFully
in interface DataInput
readFully
in interface ArrayDataInput
b
- The input buffer.off
- The requested offset into the buffer.len
- The number of bytes requested.IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public long readLArray(Object o) throws IOException
ArrayDataInput
readLArray
in interface ArrayDataInput
o
- The object to be read. This object should be a primitive
(possibly multi-dimensional) array.IOException
- if the underlying stream failed@Deprecated public String readLine() throws IOException
BufferedReader
methods.readLine
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
@Deprecated public int readPrimitiveArray(Object o) throws IOException
readLArray(Object)
insteado
- The object to be read. It must be an array of a primitive
type, or an array of Object's.IOException
- if the underlying read operation failspublic 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 void skipAllBytes(int toSkip) throws IOException
ArrayDataInput
skipAllBytes
in interface ArrayDataInput
toSkip
- the number of bytes to skipIOException
- if the underlying stream failedpublic void skipAllBytes(long toSkip) throws IOException
ArrayDataInput
skipAllBytes
in interface ArrayDataInput
toSkip
- the number of bytes to skipIOException
- if the underlying stream failedpublic int skipBytes(int toSkip) throws IOException
skipBytes
in interface DataInput
IOException
Copyright © 1996–2016 nom-tam-fits. All rights reserved.