Since: API Level 1
public interface

DataInput

java.io.DataInput
Known Indirect Subclasses

Class Overview

Defines an interface for classes that are able to read 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:

  • Only the one-, two-, and three-byte encodings are used.
  • Code points in the range U+10000U+10ffff are encoded as a surrogate pair, each of which is represented as a three-byte encoded value.
  • The code point U+0000 is encoded in two-byte form.

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.

Summary

Public Methods
abstract boolean readBoolean()
Reads a boolean.
abstract byte readByte()
Reads an 8-bit byte value.
abstract char readChar()
Reads a 16-bit character value.
abstract double readDouble()
Reads a 64-bit double value.
abstract float readFloat()
Reads a 32-bit float value.
abstract void readFully(byte[] buffer)
Reads bytes into the byte array buffer.
abstract void readFully(byte[] buffer, int offset, int count)
Reads bytes and stores them in the byte array buffer starting at offset offset.
abstract int readInt()
Reads a 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 64-bit long value.
abstract short readShort()
Reads a 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 16-bit unsigned short value and returns it as an int.
abstract int skipBytes(int count)
Skips count number of bytes.

Public Methods

public abstract boolean readBoolean ()

Since: API Level 1

Reads a boolean.

Returns
  • 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.

public abstract byte readByte ()

Since: API Level 1

Reads an 8-bit byte value.

Returns
  • 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

public abstract char readChar ()

Since: API Level 1

Reads a 16-bit character value.

Returns
  • 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

public abstract double readDouble ()

Since: API Level 1

Reads a 64-bit double value.

Returns
  • 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.

public abstract float readFloat ()

Since: API Level 1

Reads a 32-bit float value.

Returns
  • 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.

public abstract void readFully (byte[] buffer)

Since: API Level 1

Reads bytes into the byte array buffer. This method will block until buffer.length number of bytes have been read.

Parameters
buffer the buffer to read bytes into.
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.

public abstract void readFully (byte[] buffer, int offset, int count)

Since: API Level 1

Reads bytes and stores them in the byte array buffer starting at offset offset. This method blocks until count number of bytes have been read.

Parameters
buffer the byte array in which to store the bytes read.
offset the initial position in buffer to store the bytes read.
count the maximum number of bytes to store in buffer.
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.

public abstract int readInt ()

Since: API Level 1

Reads a 32-bit integer value.

Returns
  • 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

public abstract String readLine ()

Since: API Level 1

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
  • 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.

public abstract long readLong ()

Since: API Level 1

Reads a 64-bit long value.

Returns
  • 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

public abstract short readShort ()

Since: API Level 1

Reads a 16-bit short value.

Returns
  • 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

public abstract String readUTF ()

Since: API Level 1

Reads a string encoded with modified UTF-8.

Returns
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.

public abstract int readUnsignedByte ()

Since: API Level 1

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

Returns
  • 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

public abstract int readUnsignedShort ()

Since: API Level 1

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

Returns
  • 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

public abstract int skipBytes (int count)

Since: API Level 1

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 the number of bytes to skip.
Returns
  • the number of bytes actually skipped.
Throws
IOException if a problem occurs during skipping.