Package java.io
Interface DataInput
-
- All Known Subinterfaces:
ObjectInput
- All Known Implementing Classes:
DataInputStream,ObjectInputStream,RandomAccessFile
public interface DataInputDefines an interface for classes that are able to read big-endian typed data from some source. Typically, this data has been written by a class which implementsDataOutput. 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
DataInputandDataOutputuse 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+10000…U+10ffffare encoded as a surrogate pair, each of which is represented as a three-byte encoded value. - The code point
U+0000is 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.
- See Also:
DataInputStream,RandomAccessFile
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanreadBoolean()Reads a boolean.bytereadByte()Reads an 8-bit byte value.charreadChar()Reads a big-endian 16-bit character value.doublereadDouble()Reads a big-endian 64-bit double value.floatreadFloat()Reads a big-endian 32-bit float value.voidreadFully(byte[] dst)Equivalent toreadFully(dst, 0, dst.length);.voidreadFully(byte[] dst, int offset, int byteCount)ReadsbyteCountbytes from this stream and stores them in the byte arraydststarting atoffset.intreadInt()Reads a big-endian 32-bit integer value.StringreadLine()Returns a string containing the next line of text available from this stream.longreadLong()Reads a big-endian 64-bit long value.shortreadShort()Reads a big-endian 16-bit short value.intreadUnsignedByte()Reads an unsigned 8-bit byte value and returns it as an int.intreadUnsignedShort()Reads a big-endian 16-bit unsigned short value and returns it as an int.StringreadUTF()Reads a string encoded withmodified UTF-8.intskipBytes(int count)Skipscountnumber of bytes.
-
-
-
Method Detail
-
readBoolean
boolean readBoolean() throws IOExceptionReads 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.- See Also:
DataOutput.writeBoolean(boolean)
-
readByte
byte readByte() throws IOExceptionReads 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:
DataOutput.writeByte(int)
-
readChar
char readChar() throws IOExceptionReads a big-endian 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:
DataOutput.writeChar(int)
-
readDouble
double readDouble() throws IOExceptionReads a big-endian 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.- See Also:
DataOutput.writeDouble(double)
-
readFloat
float readFloat() throws IOExceptionReads a big-endian 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.- See Also:
DataOutput.writeFloat(float)
-
readFully
void readFully(byte[] dst) throws IOExceptionEquivalent toreadFully(dst, 0, dst.length);.- Throws:
IOException
-
readFully
void readFully(byte[] dst, int offset, int byteCount) throws IOExceptionReadsbyteCountbytes from this stream and stores them in the byte arraydststarting atoffset. IfbyteCountis zero, then this method returns without reading any bytes. Otherwise, this method blocks untilbyteCountbytes have been read. If insufficient bytes are available,EOFExceptionis thrown. If an I/O error occurs,IOExceptionis thrown. When an exception is thrown, some bytes may have been consumed from the stream and written into the array.- Parameters:
dst- the byte array into which the data is read.offset- the offset indstat which to store the bytes.byteCount- the number of bytes to read.- Throws:
EOFException- if the end of the source stream is reached before enough bytes have been read.IndexOutOfBoundsException- ifoffset < 0orbyteCount < 0, oroffset + byteCount > dst.length.IOException- if a problem occurs while reading from this stream.NullPointerException- ifdstis null.
-
readInt
int readInt() throws IOExceptionReads a big-endian 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:
DataOutput.writeInt(int)
-
readLine
String readLine() throws IOException
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.
-
readLong
long readLong() throws IOExceptionReads a big-endian 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:
DataOutput.writeLong(long)
-
readShort
short readShort() throws IOExceptionReads a big-endian 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:
DataOutput.writeShort(int)
-
readUnsignedByte
int readUnsignedByte() throws IOExceptionReads 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:
DataOutput.writeByte(int)
-
readUnsignedShort
int readUnsignedShort() throws IOExceptionReads a big-endian 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:
DataOutput.writeShort(int)
-
readUTF
String readUTF() throws IOException
Reads a string encoded withmodified UTF-8.- Returns:
- the next string encoded with
modified UTF-8. - 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:
DataOutput.writeUTF(java.lang.String)
-
skipBytes
int skipBytes(int count) throws IOExceptionSkipscountnumber of bytes. This method will not throw anEOFExceptionif the end of the input is reached beforecountbytes 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.
-
-