Last Updated : 28 Mar, 2024
Java InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents an input stream of bytes. Applications that are defining a subclass of the Java InputStream class must provide a method, that returns the next byte of input. A reset() method is invoked which re-positions the stream to the recently marked position.
Declaration of Java InputStream Classpublic abstract class InputStreamConstructor of InputStream Class in Java
extends Object
implements Closeable
There is a constructor used with InputStream is mentioned below:
Java.io.InputStream.mark(int arg) marks the current position of the input stream. It sets readlimit i.e. maximum number of bytes that can be read before mark position becomes invalid.
Syntax :public void mark(int arg)2. read()Parameters :
arg : integer specifying the read limit of the input StreamReturn :
void
java.io.InputStream.read() reads next byte of data from the Input Stream. The value byte is returned in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.
Syntax :public abstract int read()3. close()Parameters :
------Return :
Reads next data else, -1 i.e. when end of file is reached.Exception :
-> IOException : If I/O error occurs.
java.io.InputStream.close() closes the input stream and releases system resources associated with this stream to Garbage Collector.
Syntax :public void close()4. read() :Parameters :
------Return :
voidException :
-> IOException : If I/O error occurs.
Java.io.InputStream.read(byte[] arg) reads number of bytes of arg.length from the input stream to the buffer array arg. The bytes read by read() method are returned as int. If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte.
Syntax : public int read(byte[] arg)5. reset() :Parameters :
arg : array whose number of bytes to be readReturn :
reads number of bytes and return to the buffer else, -1 i.e. when end of file is reached.Exception :
-> IOException : If I/O error occurs.
-> NullPointerException : if arg is null.
Java.io.InputStream.reset() is invoked by mark() method. It repositions the input stream to the marked position.
Syntax :public void reset()6. markSupported() :Parameters :
----Return :
voidException :
-> IOException : If I/O error occurs.
Java.io.InputStream.markSupported() method tests if this input stream supports the mark and reset methods. The markSupported method of InputStream returns false by default.
Syntax :public boolean markSupported()7. skip() :Parameters :
-------Return :
true if input stream supports the mark() and reset() method else,false
Java.io.InputStream.skip(long arg) skips and discards arg bytes in the input stream.
Syntax :public long skip(long arg)Parameters :
arg : no. of bytes to be skippedReturn :
skip bytes.Exception :
-> IOException : If I/O error occurs.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4