Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DataInput

public interface DataInput

java.io.DataInput
Known Indirect Subclasses


Defines an interface for classes that are able to read big-endian typed data from some source. Typically, this data has been written by a class which implements DataOutput. Types that can be read include byte, 16-bit short, 32-bit int, 32-bit float, 64-bit long, 64-bit double, byte strings, and MUTF-8 strings.

MUTF-8 (Modified UTF-8) Encoding

When encoding strings as UTF, implementations of DataInput and DataOutput use a slightly modified form of UTF-8, hereafter referred to as MUTF-8. This form is identical to standard UTF-8, except:

Please refer to The Unicode Standard for further information about character encoding. MUTF-8 is actually closer to the (relatively less well-known) encoding CESU-8 than to UTF-8 per se.

See also:

Summary

Public methods

abstract boolean readBoolean()

Reads a boolean.

abstract byte readByte()

Reads an 8-bit byte value.

abstract char readChar()

Reads a big-endian 16-bit character value.

abstract double readDouble()

Reads a big-endian 64-bit double value.

abstract float readFloat()

Reads a big-endian 32-bit float value.

abstract void readFully(byte[] dst)

Equivalent to readFully(dst, 0, dst.length);.

abstract void readFully(byte[] dst, int offset, int byteCount)

Reads byteCount bytes from this stream and stores them in the byte array dst starting at offset.

abstract int readInt()

Reads a big-endian 32-bit integer value.

abstract String readLine()

Returns a string containing the next line of text available from this stream.

abstract long readLong()

Reads a big-endian 64-bit long value.

abstract short readShort()

Reads a big-endian 16-bit short value.

abstract String readUTF()

Reads a string encoded with modified UTF-8.

abstract int readUnsignedByte()

Reads an unsigned 8-bit byte value and returns it as an int.

abstract int readUnsignedShort()

Reads a big-endian 16-bit unsigned short value and returns it as an int.

abstract int skipBytes(int count)

Skips count number of bytes.

Public methods

readBoolean

Added in API level 1
boolean readBoolean ()

Reads a boolean.

Returns
boolean the next boolean value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readByte

Added in API level 1
byte readByte ()

Reads an 8-bit byte value.

Returns
byte the next byte value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readChar

Added in API level 1
char readChar ()

Reads a big-endian 16-bit character value.

Returns
char the next char value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readDouble

Added in API level 1
double readDouble ()

Reads a big-endian 64-bit double value.

Returns
double the next double value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readFloat

Added in API level 1
float readFloat ()

Reads a big-endian 32-bit float value.

Returns
float the next float value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readFully

Added in API level 1
void readFully (byte[] dst)

Equivalent to readFully(dst, 0, dst.length);.

Parameters
dst byte
Throws
IOException

readFully

Added in API level 1
void readFully (byte[] dst, 
                int offset, 
                int byteCount)

Reads byteCount bytes from this stream and stores them in the byte array dst starting at offset. If byteCount is zero, then this method returns without reading any bytes. Otherwise, this method blocks until byteCount bytes have been read. If insufficient bytes are available, EOFException is thrown. If an I/O error occurs, IOException is thrown. When an exception is thrown, some bytes may have been consumed from the stream and written into the array.

Parameters
dst byte: the byte array into which the data is read.
offset int: the offset in dst at which to store the bytes.
byteCount int: the number of bytes to read.
Throws
EOFException if the end of the source stream is reached before enough bytes have been read.
IndexOutOfBoundsException if offset < 0 or byteCount < 0, or offset + byteCount > dst.length.
IOException if a problem occurs while reading from this stream.
NullPointerException if dst is null.

readInt

Added in API level 1
int readInt ()

Reads a big-endian 32-bit integer value.

Returns
int the next int value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readLine

Added in API level 1
String readLine ()

Returns a string containing the next line of text available from this stream. A line is made of zero or more characters followed by '\n', '\r', "\r\n" or the end of the stream. The string does not include the newline sequence.

Returns
String the contents of the line or null if no characters have been read before the end of the stream.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

readLong

Added in API level 1
long readLong ()

Reads a big-endian 64-bit long value.

Returns
long the next long value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readShort

Added in API level 1
short readShort ()

Reads a big-endian 16-bit short value.

Returns
short the next short value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readUTF

Added in API level 1
String readUTF ()

Reads a string encoded with modified UTF-8.

Returns
String the next string encoded with modified UTF-8.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readUnsignedByte

Added in API level 1
int readUnsignedByte ()

Reads an unsigned 8-bit byte value and returns it as an int.

Returns
int the next unsigned byte value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

readUnsignedShort

Added in API level 1
int readUnsignedShort ()

Reads a big-endian 16-bit unsigned short value and returns it as an int.

Returns
int the next unsigned short value.
Throws
EOFException if the end of the input is reached before the read request can be satisfied.
IOException if an I/O error occurs while reading.

See also:

skipBytes

Added in API level 1
int skipBytes (int count)

Skips count number of bytes. This method will not throw an EOFException if the end of the input is reached before count bytes where skipped.

Parameters
count int: the number of bytes to skip.
Returns
int the number of bytes actually skipped.
Throws
IOException if a problem occurs during skipping.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.