Build 1.0_r1(from source)

java.io
Class DataInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.DataInputStream
All Implemented Interfaces:
Closeable, DataInput

public class DataInputStream
extends FilterInputStream
implements DataInput

DataInputStream is a filter class which can read typed data from a Stream. 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 UTF Strings.

See Also:
DataOutputStream

Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DataInputStream(InputStream in)
          Constructs a new DataInputStream on the InputStream in.
 
Method Summary
(package private)  String decodeUTF(int utfSize)
           
 int read(byte[] buffer)
          Reads bytes from the source stream into the byte array buffer.
 int read(byte[] buffer, int offset, int length)
          Read at most length bytes from this DataInputStream and stores them in byte array buffer starting at offset.
 boolean readBoolean()
          Reads a boolean from this stream.
 byte readByte()
          Reads an 8-bit byte value from this stream.
 char readChar()
          Reads a 16-bit character value from this stream.
 double readDouble()
          Reads a 64-bit double value from this stream.
 float readFloat()
          Reads a 32-bit float value from this stream.
 void readFully(byte[] buffer)
          Reads bytes from this stream into the byte array buffer.
 void readFully(byte[] buffer, int offset, int length)
          Reads bytes from this stream and stores them in the byte array buffer starting at the position offset.
 int readInt()
          Reads a 32-bit integer value from this stream.
 String readLine()
          Deprecated. Use BufferedReader
 long readLong()
          Reads a 64-bit long value from this stream.
 short readShort()
          Reads a 16-bit short value from this stream.
 int readUnsignedByte()
          Reads an unsigned 8-bit byte value from this stream and returns it as an int.
 int readUnsignedShort()
          Reads a 16-bit unsigned short value from this stream and returns it as an int.
 String readUTF()
          Reads a UTF format String from this Stream.
static String readUTF(DataInput in)
          Reads a UTF format String from the DataInput Stream in.
 int skipBytes(int count)
          Skips count number of bytes in this stream.
 
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)
Constructs a new DataInputStream on the InputStream in. All reads can now be 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.

Parameters:
in - the target InputStream to filter reads on.
See Also:
DataOutputStream, RandomAccessFile
Method Detail

read

public final int read(byte[] buffer)
               throws IOException
Reads bytes from the source stream into the byte array buffer. The number of bytes actually read is returned.

Overrides:
read in class FilterInputStream
Parameters:
buffer - the buffer to read bytes into
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.write(byte[]), DataOutput.write(byte[], int, int)

read

public final int read(byte[] buffer,
                      int offset,
                      int length)
               throws IOException
Read at most length bytes from this DataInputStream and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Overrides:
read in class FilterInputStream
Parameters:
buffer - the byte array in which to store the read bytes.
offset - the offset in buffer to store the read bytes.
length - the maximum number of bytes to store in buffer.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.write(byte[]), DataOutput.write(byte[], int, int)

readBoolean

public final boolean readBoolean()
                          throws IOException
Reads a boolean from this stream.

Specified by:
readBoolean in interface DataInput
Returns:
the next boolean value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeBoolean(boolean)

readByte

public final byte readByte()
                    throws IOException
Reads an 8-bit byte value from this stream.

Specified by:
readByte in interface DataInput
Returns:
the next byte value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeByte(int)

readChar

public final char readChar()
                    throws IOException
Reads a 16-bit character value from this stream.

Specified by:
readChar in interface DataInput
Returns:
the next char value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeChar(int)

readDouble

public final double readDouble()
                        throws IOException
Reads a 64-bit double value from this stream.

Specified by:
readDouble in interface DataInput
Returns:
the next double value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeDouble(double)

readFloat

public final float readFloat()
                      throws IOException
Reads a 32-bit float value from this stream.

Specified by:
readFloat in interface DataInput
Returns:
the next float value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeFloat(float)

readFully

public final void readFully(byte[] buffer)
                     throws IOException
Reads bytes from this stream into the byte array buffer. This method will block until buffer.length number of bytes have been read.

Specified by:
readFully in interface DataInput
Parameters:
buffer - to read bytes into
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.write(byte[]), DataOutput.write(byte[], int, int)

readFully

public final void readFully(byte[] buffer,
                            int offset,
                            int length)
                     throws IOException
Reads bytes from this stream and stores them in the byte array buffer starting at the position offset. This method blocks until count bytes have been read.

Specified by:
readFully in interface DataInput
Parameters:
buffer - the byte array into which the data is read
offset - the offset the operation start at
length - the maximum number of bytes to read
Throws:
IOException - if a problem occurs while reading from this stream
EOFException - if reaches the end of the stream before enough bytes have been read
See Also:
DataInput.readFully(byte[], int, int)

readInt

public final int readInt()
                  throws IOException
Reads a 32-bit integer value from this stream.

Specified by:
readInt in interface DataInput
Returns:
the next int value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeInt(int)

readLine

@Deprecated
public final String readLine()
                      throws IOException
Deprecated. Use BufferedReader

Returns a String representing the next line of text available in this BufferedReader. A line is represented by 0 or more characters followed by '\n', '\r', "\n\r" or end of stream. The String does not include the newline sequence.

Specified by:
readLine in interface DataInput
Returns:
the contents of the line or null if no characters were read before end of stream.
Throws:
IOException - If the DataInputStream is already closed or some other IO error occurs.

readLong

public final long readLong()
                    throws IOException
Reads a 64-bit long value from this stream.

Specified by:
readLong in interface DataInput
Returns:
the next long value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeLong(long)

readShort

public final short readShort()
                      throws IOException
Reads a 16-bit short value from this stream.

Specified by:
readShort in interface DataInput
Returns:
the next short value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeShort(int)

readUnsignedByte

public final int readUnsignedByte()
                           throws IOException
Reads an unsigned 8-bit byte value from this stream and returns it as an int.

Specified by:
readUnsignedByte in interface DataInput
Returns:
the next unsigned byte value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeByte(int)

readUnsignedShort

public final int readUnsignedShort()
                            throws IOException
Reads a 16-bit unsigned short value from this stream and returns it as an int.

Specified by:
readUnsignedShort in interface DataInput
Returns:
the next unsigned short value from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeShort(int)

readUTF

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

Specified by:
readUTF in interface DataInput
Returns:
the next UTF String from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeUTF(java.lang.String)

decodeUTF

String decodeUTF(int utfSize)
           throws IOException
Throws:
IOException

readUTF

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

Parameters:
in - the input stream to read from
Returns:
the next UTF String from the source stream.
Throws:
IOException - If a problem occurs reading from this DataInputStream.
See Also:
DataOutput.writeUTF(java.lang.String)

skipBytes

public final int skipBytes(int count)
                    throws IOException
Skips count number of bytes in this stream. Subsequent read()'s will not return these bytes unless reset() is used.

Specified by:
skipBytes in interface DataInput
Parameters:
count - the number of bytes to skip.
Returns:
the number of bytes actually skipped.
Throws:
IOException - If the stream is already closed or another IOException occurs.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature