Class: java.io.DataInputStream
- public class DataInputStream
- extends FilterInputStream
- implements DataInput
DataInputStream is not necessarily safe for multithreaded access. Thread safety is optional and is the responsibility of users of methods in this class.
Inheritance
Superclass tree:- java.lang.Object
- java.io.InputStream
- java.io.FilterInputStream
- java.io.DataInputStream
Methods
-
DataInputStreamtop
public DataInputStream(InputStream in)Creates a DataInputStream that uses the specified underlying InputStream. -
readtop
public final int read(byte[] b) throws IOExceptionReads some number of bytes from the contained input stream and stores them into the buffer arrayb. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.If
bis null, aNullPointerExceptionis thrown. If the length ofbis zero, then no bytes are read and0is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value-1is returned; otherwise, at least one byte is read and stored intob.The first byte read is stored into element
b[0], the next one intob[1], and so on. The number of bytes read is, at most, equal to the length ofb. Letkbe the number of bytes actually read; these bytes will be stored in elementsb[0]throughb[k-1], leaving elementsb[k]throughb[b.length-1]unaffected.The
read(b)method has the same effect as:read(b, 0, b.length)
- Override hierarchy:
- read from FilterInputStream
- read from InputStream
-
readtop
public final int read(byte[] b, int off, int len) throws IOExceptionReads up tolenbytes of data from the contained input stream into an array of bytes. An attempt is made to read as many aslenbytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.This method blocks until input data is available, end of file is detected, or an exception is thrown.
If
lenis zero, then no bytes are read and0is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value-1is returned; otherwise, at least one byte is read and stored intob.The first byte read is stored into element
b[off], the next one intob[off+1], and so on. The number of bytes read is, at most, equal tolen. Let k be the number of bytes actually read; these bytes will be stored in elementsb[off]throughb[off+k-1], leaving elementsb[off+k]throughb[off+len-1]unaffected.In every case, elements
b[0]throughb[off]and elementsb[off+len]throughb[b.length-1]are unaffected.- Override hierarchy:
- read from FilterInputStream
- read from InputStream
-
readBooleantop
public final boolean readBoolean() throws IOExceptionSee the general contract of thereadBooleanmethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
- readBoolean from DataInput
-
readBytetop
public final byte readByte() throws IOExceptionSee the general contract of thereadBytemethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readChartop
public final char readChar() throws IOExceptionSee the general contract of thereadCharmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readDoubletop
public final double readDouble() throws IOExceptionSee the general contract of thereadDoublemethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
- readDouble from DataInput
-
readFloattop
public final float readFloat() throws IOExceptionSee the general contract of thereadFloatmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readFullytop
public final void readFully(byte[] b) throws IOExceptionSee the general contract of thereadFullymethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readFullytop
public final void readFully(byte[] b, int off, int len) throws IOExceptionSee the general contract of thereadFullymethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readInttop
public final int readInt() throws IOExceptionSee the general contract of thereadIntmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readLinetop
See the general contract of thereadLinemethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readLongtop
public final long readLong() throws IOExceptionSee the general contract of thereadLongmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readShorttop
public final short readShort() throws IOExceptionSee the general contract of thereadShortmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readUTFtop
public final String readUTF() throws IOExceptionSee the general contract of thereadUTFmethod ofDataInput.Bytes for this operation are read from the contained input stream.
-
readUTFtop
Reads from the streamina representation of a Unicode character string encoded in modified UTF-8 format; this string of characters is then returned as aString. The details of the modified UTF-8 representation are exactly the same as for thereadUTFmethod ofDataInput. -
readUnsignedBytetop
public final int readUnsignedByte() throws IOExceptionSee the general contract of thereadUnsignedBytemethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
- readUnsignedByte from DataInput
-
readUnsignedShorttop
public final int readUnsignedShort() throws IOExceptionSee the general contract of thereadUnsignedShortmethod ofDataInput.Bytes for this operation are read from the contained input stream.
- Specified by:
- readUnsignedShort from DataInput
-
skipBytestop
public final int skipBytes(int n) throws IOExceptionSee the general contract of theskipBytesmethod ofDataInput.Bytes for this operation are read from the contained input stream.
