Skip to content

Most visited

Recently visited

navigation
Added in API level 1

DataInputStream

public class DataInputStream
extends FilterInputStream implements DataInput

java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.io.DataInputStream


Wraps an existing InputStream and reads big-endian typed data from it. Typically, this stream has been written by a DataOutputStream. 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 strings encoded in modified UTF-8.

See also:

Summary

Inherited fields

From class java.io.FilterInputStream

Public constructors

DataInputStream(InputStream in)

Constructs a new DataInputStream on the InputStream in.

Public methods

final int read(byte[] buffer, int byteOffset, int byteCount)

Reads up to byteCount bytes from this stream and stores them in the byte array buffer starting at byteOffset.

final int read(byte[] buffer)

Equivalent to read(buffer, 0, buffer.length).

final boolean readBoolean()

Reads a boolean.

final byte readByte()

Reads an 8-bit byte value.

final char readChar()

Reads a big-endian 16-bit character value.

final double readDouble()

Reads a big-endian 64-bit double value.

final float readFloat()

Reads a big-endian 32-bit float value.

final void readFully(byte[] dst)

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

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

final int readInt()

Reads a big-endian 32-bit integer value.

final String readLine()

This method was deprecated in API level 1. This method cannot be trusted to convert bytes to characters correctly. Wrap this stream with a BufferedReader instead.

final long readLong()

Reads a big-endian 64-bit long value.

final short readShort()

Reads a big-endian 16-bit short value.

final static String readUTF(DataInput in)
final String readUTF()

Reads a string encoded with modified UTF-8.

final int readUnsignedByte()

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

final int readUnsignedShort()

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

final int skipBytes(int count)

Skips count number of bytes in this stream.

Inherited methods

From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.DataInput
From interface java.lang.AutoCloseable

Public constructors

DataInputStream

Added in API level 1
DataInputStream (InputStream in)

Constructs a new DataInputStream on the InputStream in. All reads are then filtered through this stream. Note that data read by this stream is not in a human readable format and was most likely created by a DataOutputStream.

Warning: passing a null source creates an invalid DataInputStream. All operations on such a stream will fail.

Parameters
in InputStream: the source InputStream the filter reads from.

See also:

Public methods

read

Added in API level 1
int read (byte[] buffer, 
                int byteOffset, 
                int byteCount)

Reads up to byteCount bytes from this stream and stores them in the byte array buffer starting at byteOffset. Returns the number of bytes actually read or -1 if the end of the stream has been reached.

Parameters
buffer byte
byteOffset int
byteCount int
Returns
int
Throws
IOException

read

Added in API level 1
int read (byte[] buffer)

Equivalent to read(buffer, 0, buffer.length).

Parameters
buffer byte
Returns
int
Throws
IOException

readBoolean

Added in API level 1
boolean readBoolean ()

Reads a boolean.

Returns
boolean the next boolean value.
Throws
IOException

readByte

Added in API level 1
byte readByte ()

Reads an 8-bit byte value.

Returns
byte the next byte value.
Throws
IOException

readChar

Added in API level 1
char readChar ()

Reads a big-endian 16-bit character value.

Returns
char the next char value.
Throws
IOException

readDouble

Added in API level 1
double readDouble ()

Reads a big-endian 64-bit double value.

Returns
double the next double value.
Throws
IOException

readFloat

Added in API level 1
float readFloat ()

Reads a big-endian 32-bit float value.

Returns
float the next float value.
Throws
IOException

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
IOException

readInt

Added in API level 1
int readInt ()

Reads a big-endian 32-bit integer value.

Returns
int the next int value.
Throws
IOException

readLine

Added in API level 1
String readLine ()

This method was deprecated in API level 1.
This method cannot be trusted to convert bytes to characters correctly. Wrap this stream with a BufferedReader instead.

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
IOException

readLong

Added in API level 1
long readLong ()

Reads a big-endian 64-bit long value.

Returns
long the next long value.
Throws
IOException

readShort

Added in API level 1
short readShort ()

Reads a big-endian 16-bit short value.

Returns
short the next short value.
Throws
IOException

readUTF

Added in API level 1
String readUTF (DataInput in)

Parameters
in DataInput
Returns
String
Throws
IOException

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
IOException

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
IOException

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
IOException

skipBytes

Added in API level 1
int skipBytes (int count)

Skips count number of bytes in this stream. Subsequent read()s will not return these bytes unless reset() is used. 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.

See also:

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.