Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8. (For more information, see X/Open Company Ltd., "File System Safe UCS Transformation Format (FSS_UTF)", X/Open Preliminary Specification, Document Number: P316. This information also appears in ISO/IEC 10646, Annex P.)
All characters in the range '\u0001'
to '\u007F'
are represented by a single byte:
0 | bits 0-7 |
The null character '\u0000'
and characters in the range '\u0080'
to '\u07FF'
are represented by a pair of bytes:
1 | 1 | 0 | bits 6-10 |
1 | 0 | bits 0-5 |
'\u0800'
to '\uFFFF'
are represented by three bytes: 1 | 1 | 1 | 0 | bits 12-15 |
1 | 0 | bits 6-11 | ||
1 | 0 | bits 0-5 |
The two differences between this format and the "standard" UTF-8 format are the following:
'\u0000'
is encoded in 2-byte format rather than 1-byte, so that the encoded strings never have embedded nulls. Constructor Detail |
public DataInputStream(InputStream in)
FilterInputStream
and saves its argument, the input stream in
, for later use. An internalin
- the input stream.Method Detail |
public final int read(byte[] b)
read
method of DataInput
. Bytes for this operation are read from the contained input stream.
b
- the buffer into which the data is read.-1
if there is no more data because the end of the stream has been reached.IOException
- if an I/O error occurs.public final int read(byte[] b, int off, int len)
read
method of DataInput
. Bytes for this operation are read from the contained input stream.
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the maximum number of bytes read.-1
if there is no more data because the end of the stream has been reached.IOException
- if an I/O error occurs.public final void readFully(byte[] b)
readFully
method of DataInput
. Bytes for this operation are read from the contained input stream.
b
- the buffer into which the data is read.EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- if an I/O error occurs.public final void readFully(byte[] b, int off, int len)
readFully
method of DataInput
. Bytes for this operation are read from the contained input stream.
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes to read.EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- if an I/O error occurs.public final int skipBytes(int n)
skipBytes
method of DataInput
. Bytes for this operation are read from the contained input stream.
n
- the number of bytes to be skipped.IOException
- if an I/O error occurs.public final boolean readBoolean()
readBoolean
method of DataInput
. Bytes for this operation are read from the contained input stream.
boolean
value read.EOFException
- if this input stream has reached the end.IOException
- if an I/O error occurs.public final byte readByte()
readByte
method of DataInput
. Bytes for this operation are read from the contained input stream.
byte
.EOFException
- if this input stream has reached the end.IOException
- if an I/O error occurs.public final int readUnsignedByte()
readUnsignedByte
method of DataInput
. Bytes for this operation are read from the contained input stream.
EOFException
- if this input stream has reached the end.IOException
- if an I/O error occurs.public final short readShort()
readShort
method of DataInput
. Bytes for this operation are read from the contained input stream.
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- if an I/O error occurs.public final int readUnsignedShort()
readUnsignedShort
method of DataInput
. Bytes for this operation are read from the contained input stream.
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- if an I/O error occurs.public final char readChar()
readChar
method of DataInput
. Bytes for this operation are read from the contained input stream.
EOFException
- if this input stream reaches the end before reading two bytes.IOException
- if an I/O error occurs.public final int readInt()
readInt
method of DataInput
. Bytes for this operation are read from the contained input stream.
int
.EOFException
- if this input stream reaches the end before reading four bytes.IOException
- if an I/O error occurs.public final long readLong()
readLong
method of DataInput
. Bytes for this operation are read from the contained input stream.
long
.EOFException
- if this input stream reaches the end before reading eight bytes.IOException
- if an I/O error occurs.public final float readFloat()
readFloat
method of DataInput
. Bytes for this operation are read from the contained input stream.
float
.EOFException
- if this input stream reaches the end before reading four bytes.IOException
- if an I/O error occurs.public final double readDouble()
readDouble
method of DataInput
. Bytes for this operation are read from the contained input stream.
double
.EOFException
- if this input stream reaches the end before reading eight bytes.IOException
- if an I/O error occurs.public final String readLine()
BufferedReader.readLine()
method. Programs that use the DataInputStream
class to read lines can be converted to use the BufferedReader
class by replacing code of the form: with:DataInputStream d = new DataInputStream(in);
BufferedReader d = new BufferedReader(new InputStreamReader(in));
readLine
method of DataInput
. Bytes for this operation are read from the contained input stream.
IOException
- if an I/O error occurs.public final String readUTF()
readUTF
method of DataInput
. Bytes for this operation are read from the contained input stream.
EOFException
- if this input stream reaches the end before reading all the bytes.IOException
- if an I/O error occurs.public static final String readUTF(DataInput in)
in
a representation of a Unicode character string encoded in Java 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
.in
- a data input stream.EOFException
- if the input stream reaches the end before all the bytes.IOException
- if an I/O error occurs.UTFDataFormatException
- if the bytes do not represent a valid UTF-8 encoding of a Unicode string.