All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.io.InputStream
|
+----java.io.FilterInputStream
|
+----java.io.DataInputStream
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.
byte.length
bytes of data from this data
input stream into an array of bytes.
len
bytes of data from this data input
stream into an array of bytes.
boolean
from this data input stream.
double
from this data input stream.
float
from this data input stream.
b.length
bytes from this data input stream
into the byte array.
len
bytes from this data input stream
into the byte array.
n
bytes of input in the underlying
input stream.
public DataInputStream(InputStream in)
public final int read(byte b[]) throws IOException
byte.length
bytes of data from this data
input stream into an array of bytes. This method blocks until some
input is available.
The read
method of DataInputStream
calls the read
method of its underlying input stream
with the three arguments b
, 0
, and
b.length
and returns whatever value that method returns.
-1
if there is no more data because the end
of the stream has been reached.
public final int read(byte b[],
int off,
int len) throws IOException
len
bytes of data from this data input
stream into an array of bytes. This method blocks until some input
is available.
The read
method of DataInputStream
calls the read
method of its underlying input stream
with the same arguments and returns whatever value that method returns.
-1
if there is no more data because the end
of the stream has been reached.
public final void readFully(byte b[]) throws IOException
b.length
bytes from this data input stream
into the byte array. This method reads repeatedly from the
underlying stream until all the bytes are read. This method blocks
until all the bytes are read, the end of the stream is detected,
or an exception is thrown.
public final void readFully(byte b[],
int off,
int len) throws IOException
len
bytes from this data input stream
into the byte array. This method reads repeatedly from the
underlying stream until all the bytes are read. This method blocks
until all the bytes are read, the end of the stream is detected,
or an exception is thrown.
public final int skipBytes(int n) throws IOException
n
bytes of input in the underlying
input stream. This method blocks until all the bytes are skipped,
the end of the stream is detected, or an exception is thrown.
n
.
public final boolean readBoolean() throws IOException
boolean
from this data input stream. This
method reads a single byte from the underlying input stream. A
value of 0
represents false
. Any other
value represents true
. This method blocks until
either the byte is read, the end of the stream is detected, or an
exception is thrown.
boolean
value read.
public final byte readByte() throws IOException
b
, where
0 <= b
<= 255, then the
result is:
(byte)(b)
This method blocks until either the byte is read, the end of the stream is detected, or an exception is thrown.
byte
.
public final int readUnsignedByte() throws IOException
public final short readShort() throws IOException
b1
and b2
,
where each of the two values is between 0
and
255
, inclusive, then the result is equal to:
(short)((b1 << 8) | b2)
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
public final int readUnsignedShort() throws IOException
b1
and b2
,
where 0 <= b1
,
b2 <= 255
, then the result is equal to:
(b1 << 8) | b2
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
public final char readChar() throws IOException
b1
and b2
,
where 0 <= b1
,
b1
<= 255, then the result is equal to:
(char)((b1 << 8) | b2)
This method blocks until either the two bytes are read, the end of the stream is detected, or an exception is thrown.
public final int readInt() throws IOException
b1
, b2
,
b3
, and b4
, where
0 <= b1
, b2
,
b3
, b4
<= 255, then the
result is equal to:
(b1 << 24) | (b2 << 16) + (b3 << 8) +b4
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
int
.
public final long readLong() throws IOException
b1
, b2
,
b3
, b4
, b5
,
b6
, b7
, and b8
, where
0 <= b1, b2, b3, b4, b5, b6, b7, b8 <= 255,
then the result is equal to:
((long)b1 << 56) + ((long)b2 << 48) +
((long)b3 << 40) + ((long)b4 << 32) +
((long)b5 << 24) + (b6 << 16) +
(b7 << 8) + b8
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
long
.
public final float readFloat() throws IOException
float
from this data input stream. This
method reads an int
value as if by the
readInt
method and then converts that
int
to a float
using the
intBitsToFloat
method in class Float
.
This method blocks until the four bytes are read, the end of the
stream is detected, or an exception is thrown.
float
.
public final double readDouble() throws IOException
double
from this data input stream. This
method reads a long
value as if by the
readLong
method and then converts that
long
to a double
using the
longBitsToDouble
method in class Double
.
This method blocks until the eight bytes are read, the end of the stream is detected, or an exception is thrown.
double
.
public final String readLine() throws IOException
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
DataInputStream d = new DataInputStream(in);
BufferedReader d
= new BufferedReader(new InputStreamReader(in));
A line of text is terminated by a carriage return character
('\r'
), a newline character ('\n'
), a
carriage return character immediately followed by a newline
character, or the end of the input stream. The line-terminating
character(s), if any, are not returned as part of the string that
is returned.
This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the stream is detected, or an exception is thrown.
public final String readUTF() throws IOException
readUTF(this)
.
See readUTF(java.io.DataInput)
for a more
complete description of the format.
This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.
public static final String readUTF(DataInput in) throws IOException
The first two bytes are read as if by
readUnsignedShort
. This value gives the number of
following bytes that are in the encoded string, not
the length of the resulting string. The following bytes are then
interpreted as bytes encoding characters in the UTF-8 format
and are converted into characters.
This method blocks until all the bytes are read, the end of the stream is detected, or an exception is thrown.
All Packages Class Hierarchy This Package Previous Next Index