InputStream

abstract class InputStream : AutoCloseable

This abstract class is the superclass of all classes representing an input stream of bytes.

Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input.

Author

Arthur van Hoff

Since

1.0

See also

java.io.BufferedInputStream
java.io.ByteArrayInputStream
java.io.DataInputStream
java.io.FilterInputStream
java.io.InputStream.read
java.io.OutputStream
java.io.PushbackInputStream

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open fun available(): Int

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Link copied to clipboard
open override fun close()

Closes this input stream and releases any system resources associated with the stream.

Link copied to clipboard
open fun mark(readlimit: Int)

Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

Link copied to clipboard

Tests if this input stream supports the mark and reset methods. Whether or not mark and reset are supported is an invariant property of a particular input stream instance.

Link copied to clipboard
abstract fun read(): Int

Reads the next byte of data from the input stream. The value byte is returned as an int 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. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

open fun read(b: ByteArray): Int

Reads some number of bytes from the input stream and stores them into the buffer array b. 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.

open fun read(b: ByteArray, off: Int, len: Int): Int

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

Link copied to clipboard
open fun readAllBytes(): ByteArray?

Reads all remaining bytes from the input stream. This method blocks until all remaining bytes have been read and end of stream is detected, or an exception is thrown. This method does not close the input stream.

Link copied to clipboard
open fun readNBytes(len: Int): ByteArray?

Reads up to a specified number of bytes from the input stream. This method blocks until the requested number of bytes has been read, end of stream is detected, or an exception is thrown. This method does not close the input stream.

open fun readNBytes(b: ByteArray, off: Int, len: Int): Int

Reads the requested number of bytes from the input stream into the given byte array. This method blocks until len bytes of input data have been read, end of stream is detected, or an exception is thrown. The number of bytes actually read, possibly zero, is returned. This method does not close the input stream.

Link copied to clipboard
open fun reset()

Repositions this stream to the position at the time the mark method was last called on this input stream.

Link copied to clipboard
open fun skip(n: Long): Long

Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, the skip method for class InputStream always returns 0, and no bytes are skipped. Subclasses may handle the negative value differently.

Link copied to clipboard
open fun skipNBytes(n: Long)

Skips over and discards exactly n bytes of data from this input stream. If n is zero, then no bytes are skipped. If n is negative, then no bytes are skipped. Subclasses may handle the negative value differently.

Link copied to clipboard
open fun transferTo(out: OutputStream): Long

Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. On return, this input stream will be at end of stream. This method does not close either stream.