java.io
Class DataInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--java.io.DataInputStream
All Implemented Interfaces:
DataInput

public class DataInputStream
extends FilterInputStream
implements DataInput

A data input stream that lets you read primitive Java data types from a stream in a portable way. Primitive data types are well understood types with associated operations. For example, Integers are considered primitive data types.

See Also:
DataOutputStream

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DataInputStream(InputStream in)
          Creates a new DataInputStream.
 
Method Summary
 int read(byte[] b)
          Reads data into an array of bytes.
 int read(byte[] b, int off, int len)
          Reads data into an array of bytes.
 boolean readBoolean()
          Reads a boolean.
 byte readByte()
          Reads an 8 bit byte.
 char readChar()
          Reads a 16 bit char.
 double readDouble()
          Reads a 64 bit double.
 float readFloat()
          Reads a 32 bit float.
 void readFully(byte[] b)
          Reads bytes, blocking until all bytes are read.
 void readFully(byte[] b, int off, int len)
          Reads bytes, blocking until all bytes are read.
 int readInt()
          Reads a 32 bit int.
 String readLine()
          Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
 long readLong()
          Reads a 64 bit long.
 short readShort()
          Reads a 16 bit short.
 int readUnsignedByte()
          Reads an unsigned 8 bit byte.
 int readUnsignedShort()
          Reads 16 bit short.
 String readUTF()
          Reads a UTF format String.
static String readUTF(DataInput in)
          Reads a UTF format String from the given input stream.
 int skipBytes(int n)
          Skips bytes, blocks until all bytes are skipped.
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataInputStream

public DataInputStream(InputStream in)
Creates a new DataInputStream.

Parameters:
in - the input stream
Method Detail

read

public final int read(byte[] b)
               throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
Throws:
IOException - If an I/O error has occurred.

read

public final int read(byte[] b,
                      int off,
                      int len)
               throws IOException
Reads data into an array of bytes. This method blocks until some input is available.

Overrides:
read in class FilterInputStream
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
Throws:
IOException - If an I/O error has occurred.

readFully

public final void readFully(byte[] b)
                     throws IOException
Reads bytes, blocking until all bytes are read.

Specified by:
readFully in interface DataInput
Parameters:
b - the buffer into which the data is read
Throws:
IOException - If an I/O error has occurred.
EOFException - If EOF reached before all bytes are read.

readFully

public final void readFully(byte[] b,
                            int off,
                            int len)
                     throws IOException
Reads bytes, blocking until all bytes are read.

Specified by:
readFully in interface DataInput
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
Throws:
IOException - If an I/O error has occurred.
EOFException - If EOF reached before all bytes are read.

skipBytes

public final int skipBytes(int n)
                    throws IOException
Skips bytes, blocks until all bytes are skipped.

Specified by:
skipBytes in interface DataInput
Parameters:
n - the number of bytes to be skipped
Returns:
the actual number of bytes skipped.
Throws:
IOException - If an I/O error has occurred.

readBoolean

public final boolean readBoolean()
                          throws IOException
Reads a boolean.

Specified by:
readBoolean in interface DataInput
Returns:
the boolean read.
Throws:
IOException - If other I/O error has occurred.

readByte

public final byte readByte()
                    throws IOException
Reads an 8 bit byte.

Specified by:
readByte in interface DataInput
Returns:
the 8 bit byte read.
Throws:
IOException - If other I/O error has occurred.

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
Reads an unsigned 8 bit byte.

Specified by:
readUnsignedByte in interface DataInput
Returns:
the 8 bit byte read.
Throws:
IOException - If other I/O error has occurred.

readShort

public final short readShort()
                      throws IOException
Reads a 16 bit short.

Specified by:
readShort in interface DataInput
Returns:
the 16 bit short read.
Throws:
IOException - If other I/O error has occurred.

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
Reads 16 bit short.

Specified by:
readUnsignedShort in interface DataInput
Returns:
the 16 bit short read.
Throws:
IOException - If other I/O error has occurred.

readChar

public final char readChar()
                    throws IOException
Reads a 16 bit char.

Specified by:
readChar in interface DataInput
Returns:
the read 16 bit char.
Throws:
IOException - If other I/O error has occurred.

readInt

public final int readInt()
                  throws IOException
Reads a 32 bit int.

Specified by:
readInt in interface DataInput
Returns:
the 32 bit integer read.
Throws:
IOException - If other I/O error has occurred.

readLong

public final long readLong()
                    throws IOException
Reads a 64 bit long.

Specified by:
readLong in interface DataInput
Returns:
the 64 bit long read.
Throws:
IOException - If other I/O error has occurred.

readFloat

public final float readFloat()
                      throws IOException
Reads a 32 bit float.

Specified by:
readFloat in interface DataInput
Returns:
the read 32 bit float.
Throws:
IOException - If other I/O error has occurred.

readDouble

public final double readDouble()
                        throws IOException
Reads a 64 bit double.

Specified by:
readDouble in interface DataInput
Returns:
the 64 bit double read.
Throws:
IOException - If other I/O error has occurred.

readLine

public final String readLine()
                      throws IOException
Reads in a line that has been terminated by a \n, \r, \r\n or EOF.

Specified by:
readLine in interface DataInput
Returns:
a String copy of the line.
IOException

readUTF

public final String readUTF()
                     throws IOException
Reads a UTF format String.

Specified by:
readUTF in interface DataInput
Returns:
the String.
IOException

readUTF

public static final String readUTF(DataInput in)
                            throws IOException
Reads a UTF format String from the given input stream.

Returns:
the String.
IOException