| |
|
| java.lang.Object java.io.InputStream java.io.FilterInputStream java.io.DataInputStream
DataInputStream | public class DataInputStream extends FilterInputStream implements DataInput(Code) | | A data input stream lets an application read primitive Java data
types from an underlying input stream in a machine-independent
way. An application uses a data output stream to write data that
can later be read by a data input stream.
DataInputStream is not necessarily safe for multithreaded access.
Thread safety is optional and is the responsibility of users of
methods in this class.
author: Arthur van Hoff version: 1.83, 05/05/07 See Also: java.io.DataOutputStream since: JDK1.0 |
Constructor Summary | |
public | DataInputStream(InputStream in) Creates a DataInputStream that uses the specified
underlying InputStream. |
Method Summary | |
final public int | read(byte b) Reads some number of bytes from the contained input stream and
stores them into the buffer array b . | final public int | read(byte b, int off, int len) Reads up to len bytes of data from the contained
input stream into an array of bytes. | final public boolean | readBoolean() See the general contract of the readBoolean
method of DataInput . | final public byte | readByte() See the general contract of the readByte
method of DataInput . | final public char | readChar() See the general contract of the readChar
method of DataInput . | final public double | readDouble() See the general contract of the readDouble
method of DataInput . | final public float | readFloat() See the general contract of the readFloat
method of DataInput . | final public void | readFully(byte b) See the general contract of the readFully
method of DataInput . | final public void | readFully(byte b, int off, int len) See the general contract of the readFully
method of DataInput . | final public int | readInt() See the general contract of the readInt
method of DataInput . | final public String | readLine() See the general contract of the readLine
method of DataInput . | final public long | readLong() See the general contract of the readLong
method of DataInput . | final public short | readShort() See the general contract of the readShort
method of DataInput . | final public String | readUTF() See the general contract of the readUTF
method of DataInput . | final public static String | readUTF(DataInput in) Reads from the
stream in a representation
of a Unicode character string encoded in
modified UTF-8 format;
this string of characters is then returned as a String .
The details of the modified UTF-8 representation
are exactly the same as for the readUTF
method of DataInput .
Parameters: in - a data input stream. | final public int | readUnsignedByte() See the general contract of the readUnsignedByte
method of DataInput . | final public int | readUnsignedShort() See the general contract of the readUnsignedShort
method of DataInput . | final public int | skipBytes(int n) See the general contract of the skipBytes
method of DataInput .
Bytes for this operation are read from the contained
input stream.
Parameters: n - the number of bytes to be skipped. |
DataInputStream | public DataInputStream(InputStream in)(Code) | | Creates a DataInputStream that uses the specified
underlying InputStream.
Parameters: in - the specified input stream |
read | final public int read(byte b) throws IOException(Code) | | Reads some number of bytes from the contained input stream and
stores them into the buffer array b . The number of
bytes actually read is returned as an integer. This method blocks
until input data is available, end of file is detected, or an
exception is thrown.
If b is null, a NullPointerException is
thrown. If the length of b is zero, then no bytes are
read and 0 is returned; otherwise, there is an attempt
to read at least one byte. If no byte is available because the
stream is at end of file, the value -1 is returned;
otherwise, at least one byte is read and stored into b .
The first byte read is stored into element b[0] , the
next one into b[1] , and so on. The number of bytes read
is, at most, equal to the length of b . Let k
be the number of bytes actually read; these bytes will be stored in
elements b[0] through b[k-1] , leaving
elements b[k] through b[b.length-1]
unaffected.
The read(b) method has the same effect as:
read(b, 0, b.length)
Parameters: b - the buffer into which the data is read. the total number of bytes read into the buffer, or-1 if there is no more data because the endof the stream has been reached. exception: IOException - if the first byte cannot be read for any reasonother than end of file, the stream has been closed and the underlyinginput stream does not support reading after close, or another I/Oerror occurs. See Also: java.io.FilterInputStream.in See Also: java.io.InputStream.read(byte[]intint) |
read | final public int read(byte b, int off, int len) throws IOException(Code) | | Reads up to len bytes of data from the contained
input stream into an array of bytes. An attempt is made to read
as many as len bytes, but a smaller number may be read,
possibly zero. The number of bytes actually read is returned as an
integer.
This method blocks until input data is available, end of file is
detected, or an exception is thrown.
If len is zero, then no bytes are read and
0 is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at end of
file, the value -1 is returned; otherwise, at least one
byte is read and stored into b .
The first byte read is stored into element b[off] , the
next one into b[off+1] , and so on. The number of bytes read
is, at most, equal to len . Let k be the number of
bytes actually read; these bytes will be stored in elements
b[off] through b[off+ k-1] ,
leaving elements b[off+ k] through
b[off+len-1] unaffected.
In every case, elements b[0] through
b[off] and elements b[off+len] through
b[b.length-1] are unaffected.
Parameters: b - the buffer into which the data is read. Parameters: off - the start offset in the destination array b Parameters: len - the maximum number of bytes read. the total number of bytes read into the buffer, or-1 if there is no more data because the endof the stream has been reached. exception: NullPointerException - If b is null . exception: IndexOutOfBoundsException - If off is negative, len is negative, or len is greater than b.length - off exception: IOException - if the first byte cannot be read for any reasonother than end of file, the stream has been closed and the underlyinginput stream does not support reading after close, or another I/Oerror occurs. See Also: java.io.FilterInputStream.in See Also: java.io.InputStream.read(byte[]intint) |
readBoolean | final public boolean readBoolean() throws IOException(Code) | | See the general contract of the readBoolean
method of DataInput .
Bytes for this operation are read from the contained
input stream.
the boolean value read. exception: EOFException - if this input stream has reached the end. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readByte | final public byte readByte() throws IOException(Code) | | See the general contract of the readByte
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next byte of this input stream as a signed 8-bitbyte . exception: EOFException - if this input stream has reached the end. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readChar | final public char readChar() throws IOException(Code) | | See the general contract of the readChar
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next two bytes of this input stream, interpreted as achar . exception: EOFException - if this input stream reaches the end beforereading two bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readDouble | final public double readDouble() throws IOException(Code) | | See the general contract of the readDouble
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next eight bytes of this input stream, interpreted as adouble . exception: EOFException - if this input stream reaches the end beforereading eight bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.DataInputStream.readLong See Also: java.lang.Double.longBitsToDouble(long) |
readFloat | final public float readFloat() throws IOException(Code) | | See the general contract of the readFloat
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next four bytes of this input stream, interpreted as afloat . exception: EOFException - if this input stream reaches the end beforereading four bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.DataInputStream.readInt See Also: java.lang.Float.intBitsToFloat(int) |
readFully | final public void readFully(byte b) throws IOException(Code) | | See the general contract of the readFully
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
Parameters: b - the buffer into which the data is read. exception: EOFException - if this input stream reaches the end beforereading all the bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readFully | final public void readFully(byte b, int off, int len) throws IOException(Code) | | See the general contract of the readFully
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
Parameters: b - the buffer into which the data is read. Parameters: off - the start offset of the data. Parameters: len - the number of bytes to read. exception: EOFException - if this input stream reaches the end beforereading all the bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readInt | final public int readInt() throws IOException(Code) | | See the general contract of the readInt
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next four bytes of this input stream, interpreted as anint . exception: EOFException - if this input stream reaches the end beforereading four bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readLong | final public long readLong() throws IOException(Code) | | See the general contract of the readLong
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next eight bytes of this input stream, interpreted as along . exception: EOFException - if this input stream reaches the end beforereading eight bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readShort | final public short readShort() throws IOException(Code) | | See the general contract of the readShort
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next two bytes of this input stream, interpreted as asigned 16-bit number. exception: EOFException - if this input stream reaches the end beforereading two bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readUTF | final public String readUTF() throws IOException(Code) | | See the general contract of the readUTF
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
a Unicode string. exception: EOFException - if this input stream reaches the end beforereading all the bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. exception: UTFDataFormatException - if the bytes do not represent a validmodified UTF-8 encoding of a string. See Also: java.io.DataInputStream.readUTF(java.io.DataInput) |
readUTF | final public static String readUTF(DataInput in) throws IOException(Code) | | Reads from the
stream in a representation
of a Unicode character string encoded in
modified UTF-8 format;
this string of characters is then returned as a String .
The details of the modified UTF-8 representation
are exactly the same as for the readUTF
method of DataInput .
Parameters: in - a data input stream. a Unicode string. exception: EOFException - if the input stream reaches the endbefore all the bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. exception: UTFDataFormatException - if the bytes do not represent avalid modified UTF-8 encoding of a Unicode string. See Also: java.io.DataInputStream.readUnsignedShort |
readUnsignedByte | final public int readUnsignedByte() throws IOException(Code) | | See the general contract of the readUnsignedByte
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next byte of this input stream, interpreted as anunsigned 8-bit number. exception: EOFException - if this input stream has reached the end. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
readUnsignedShort | final public int readUnsignedShort() throws IOException(Code) | | See the general contract of the readUnsignedShort
method of DataInput .
Bytes
for this operation are read from the contained
input stream.
the next two bytes of this input stream, interpreted as anunsigned 16-bit integer. exception: EOFException - if this input stream reaches the end beforereading two bytes. exception: IOException - the stream has been closed and the containedinput stream does not support reading after close, oranother I/O error occurs. See Also: java.io.FilterInputStream.in |
skipBytes | final public int skipBytes(int n) throws IOException(Code) | | See the general contract of the skipBytes
method of DataInput .
Bytes for this operation are read from the contained
input stream.
Parameters: n - the number of bytes to be skipped. the actual number of bytes skipped. exception: IOException - if the contained input stream does not supportseek, or the stream has been closed andthe contained input stream does not support reading after close, or another I/O error occurs. |
|
|
|