read

abstract suspend fun read(b: ByteBuffer): Int


open suspend 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.

Return

The next byte of data, or -1 if the end of the stream is reached.

Throws

If an I/O error occurs.


open suspend 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.

If the length of b is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b0, the next one into b1, and so on. The number of bytes read is, at most, equal to the length of b. Let k be the number of bytes actually read; these bytes will be stored in elements b0 through bk-1, leaving elements bk through bb.length-1 unaffected.

Parameters

b

The buffer into which the data is read.


open suspend 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.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is 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 -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element boff, the next one into boff+1, and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements boff through boff+k-1, leaving elements boff+k through boff+len-1 unaffected.

In every case, elements b0 through boff-1 and elements boff+len through bb.length-1 are unaffected.

Return

The total number of bytes read into the buffer, or -1 if there is no more data because the end of the

Parameters

b

The buffer into which the data is read.

off

The start offset in the destination array b.

len

The maximum number of bytes read.