DataInput
interface provides
for reading bytes from a binary stream and
reconstructing from them data in any of
the Java primitive types. There is also
a
facility for reconstructing a String
from data in
modified UTF-8
format.
It is generally true of all the reading
routines in this interface that if end of
file is reached before the desired number
of bytes has been read, an EOFException
(which is a kind of IOException
)
is thrown. If any byte cannot be read for
any reason other than end of file, an IOException
other than EOFException
is
thrown. In particular, an IOException
may be thrown if the input stream has been
closed.
Implementations of the DataInput and DataOutput interfaces represent Unicode strings in a format that is a slight modification of UTF-8. (For information regarding the standard UTF-8 format, see section 3.9 Unicode Encoding Forms of The Unicode Standard, Version 4.0). Note that in the following tables, the most significant bit appears in the far left-hand column.
All characters in the range '\u0001'
to
'\u007F'
are represented by a single byte:
Bit Values Byte 1
0 bits 6-0
The null character '\u0000'
and characters in the
range '\u0080'
to '\u07FF'
are
represented by a pair of bytes:
Bit Values Byte 1
1 1 0 bits 10-6 Byte 2
1 0 bits 5-0
char
values in the range '\u0800'
to
'\uFFFF'
are represented by three bytes:
Bit Values Byte 1
1 1 1 0 bits 15-12 Byte 2
1 0 bits 11-6 Byte 3
1 0 bits 5-0
The 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.
Frank
- YellinJDK1.0
- Method from java.io.DataInput Summary: |
---|
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUTF, readUnsignedByte, readUnsignedShort, skipBytes |
Method from java.io.DataInput Detail: |
---|
true if that byte is nonzero,
false if that byte is zero.
This method is suitable for reading
the byte written by the writeBoolean
method of interface DataOutput . |
-128 through 127 ,
inclusive.
This method is suitable for
reading the byte written by the writeByte
method of interface DataOutput . |
char value.
Let a
be the first byte read and b
be the second byte. The value
returned is:
This method
is suitable for reading bytes written by
the writeChar method of interface
DataOutput . |
double value. It does this
by first constructing a long
value in exactly the manner
of the readlong
method, then converting this long
value to a double in exactly
the manner of the method Double.longBitsToDouble .
This method is suitable for reading
bytes written by the writeDouble
method of interface DataOutput . |
float value. It does this
by first constructing an int
value in exactly the manner
of the readInt
method, then converting this int
value to a float in
exactly the manner of the method Float.intBitsToFloat .
This method is suitable for reading
bytes written by the writeFloat
method of interface DataOutput . |
b . The number of bytes
read is equal
to the length of b .
This method blocks until one of the following conditions occurs:
If |
len
bytes from
an input stream.
This method blocks until one of the following conditions occurs:
If |
int value. Let a-d
be the first through fourth bytes read. The value returned is:
This method is suitable
for reading bytes written by the writeInt
method of interface DataOutput . |
String . Note
that because this
method processes bytes,
it does not support input of the full Unicode
character set.
If end of file is encountered
before even one byte can be read, then |
long value. Let a-h
be the first through eighth bytes read.
The value returned is:
This method is suitable
for reading bytes written by the |
short value. Let a
be the first byte read and b
be the second byte. The value
returned
is:
This method
is suitable for reading the bytes written
by the writeShort method of
interface DataOutput . |
readUTF
is that it reads a representation of a Unicode
character string encoded in modified
UTF-8 format; this string of characters
is then returned as a String .
First, two bytes are read and used to
construct an unsigned 16-bit integer in
exactly the manner of the
If the first byte of a group
matches the bit pattern
If the first byte
of a group matches the bit pattern
If the first byte of a group
matches the bit pattern 1110xxxx ,
then the group consists of that byte a
and two more bytes b and c .
If there is no byte c (because
byte a was one of the last
two of the bytes to be read), or either
byte b or byte c
does not match the bit pattern 10xxxxxx ,
then a UTFDataFormatException
is thrown. Otherwise, the group is converted
to the character:
If the first byte of a group matches the
pattern 1111xxxx or the pattern
10xxxxxx , then a UTFDataFormatException
is thrown.
If end of file is encountered
at any time during this entire process,
then an
After every group has been converted to
a character by this process, the characters
are gathered, in the same order in which
their corresponding groups were read from
the input stream, to form a
The |
int , and returns
the result, which is therefore in the range
0
through 255 .
This method is suitable for reading
the byte written by the writeByte
method of interface DataOutput
if the argument to writeByte
was intended to be a value in the range
0 through 255 . |
int value in the range 0
through 65535 . Let a
be the first byte read and
b
be the second byte. The value returned is:
This method is suitable for reading the bytes
written by the writeShort method
of interface DataOutput if
the argument to writeShort
was intended to be a value in the range
0 through 65535 . |
n bytes
of data from the input
stream, discarding the skipped bytes. However,
it may skip
over some smaller number of
bytes, possibly zero. This may result from
any of a
number of conditions; reaching
end of file before n bytes
have been skipped is
only one possibility.
This method never throws an EOFException .
The actual
number of bytes skipped is returned. |