java.io.DataInputStream
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.
Summary
Public Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Public Constructors
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. |
Public Methods
public
final
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. Answer the number of bytes actually read or -1 if
no bytes were read and end of stream was encountered.
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. |
public
final
int
read(byte[] buffer)
Reads bytes from the source stream into the byte array
buffer. The number of bytes actually read is returned.
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. |
public
final
boolean
readBoolean()
Reads a boolean from this stream.
Returns
- the next boolean value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
byte
readByte()
Reads an 8-bit byte value from this stream.
Returns
- the next byte value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
char
readChar()
Reads a 16-bit character value from this stream.
Returns
- the next
char value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
double
readDouble()
Reads a 64-bit
double value from this stream.
Returns
- the next
double value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
float
readFloat()
Reads a 32-bit
float value from this stream.
Returns
- the next
float value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
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.
This method blocks until
count bytes have been read.
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 |
public
final
void
readFully(byte[] buffer)
Reads bytes from this stream into the byte array
buffer.
This method will block until
buffer.length number of bytes
have been read.
Parameters
| buffer
| to read bytes into |
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
int
readInt()
Reads a 32-bit integer value from this stream.
Returns
- the next
int value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
String
readLine()
This method is deprecated.
Use BufferedReader
Answers 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.
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. |
public
final
long
readLong()
Reads a 64-bit
long value from this stream.
Returns
- the next
long value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
short
readShort()
Reads a 16-bit
short value from this stream.
Returns
- the next
short value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
String
readUTF()
Reads a UTF format String from this Stream.
Returns
- the next UTF String from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
static
final
String
readUTF(DataInput in)
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. |
public
final
int
readUnsignedByte()
Reads an unsigned 8-bit
byte value from this stream and
returns it as an int.
Returns
- the next unsigned byte value from the source stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
int
readUnsignedShort()
Reads a 16-bit unsigned
short value from this stream and
returns it as an int.
Returns
- the next unsigned
short value from the source
stream.
Throws
| IOException
| If a problem occurs reading from this DataInputStream. |
public
final
int
skipBytes(int count)
Skips
count number of bytes in this stream. Subsequent
read()'s will not return these bytes unless
reset() is used.
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.
|