BufferedSource

expect sealed interface BufferedSource : Source

A source that keeps a buffer internally so that callers can do small reads without a performance penalty. It also allows clients to read ahead, buffering as much as necessary before consuming input.

Inheritors

Inheritors

actual interface BufferedSource : Source

Inheritors

Properties

Link copied to clipboard
expect abstract val buffer: Buffer

This source's internal buffer.

actual abstract val buffer: Buffer
actual abstract val buffer: Buffer

Functions

Link copied to clipboard

Returns a new source that buffers reads from source. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get an ergonomic and efficient access to data.

Link copied to clipboard

Returns a source that uses cipher to encrypt or decrypt this.

close
Link copied to clipboard
abstract override fun close()

Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.

abstract override fun close()

Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.

abstract override fun close()

Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.

Link copied to clipboard
expect abstract fun exhausted(): Boolean

Returns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.

actual abstract fun exhausted(): Boolean
actual abstract fun exhausted(): Boolean
Link copied to clipboard
inline fun Source.gzip(): GzipSource

Returns a GzipSource that gzip-decompresses this Source while reading.

Link copied to clipboard

Returns a source that uses digest to hash this.

Returns a source that uses mac to hash this.

Link copied to clipboard
expect abstract fun indexOf(b: Byte): Long

Equivalent to indexOf(b, 0).

expect abstract fun indexOf(bytes: ByteString): Long

Equivalent to indexOf(bytes, 0).

expect abstract fun indexOf(b: Byte, fromIndex: Long): Long

Returns the index of the first b in the buffer at or after fromIndex. This expands the buffer as necessary until b is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.

expect abstract fun indexOf(bytes: ByteString, fromIndex: Long): Long

Returns the index of the first match for bytes in the buffer at or after fromIndex. This expands the buffer as necessary until bytes is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.

expect abstract fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long

Returns the index of b if it is found in the range of fromIndex inclusive to toIndex exclusive. If b isn't found, or if fromIndex == toIndex, then -1 is returned.

actual abstract fun indexOf(b: Byte): Long
actual abstract fun indexOf(bytes: ByteString): Long
actual abstract fun indexOf(b: Byte, fromIndex: Long): Long
actual abstract fun indexOf(bytes: ByteString, fromIndex: Long): Long
actual abstract fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long
actual abstract fun indexOf(b: Byte): Long
actual abstract fun indexOf(bytes: ByteString): Long
actual abstract fun indexOf(b: Byte, fromIndex: Long): Long
actual abstract fun indexOf(bytes: ByteString, fromIndex: Long): Long
actual abstract fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long
Link copied to clipboard
expect abstract fun indexOfElement(targetBytes: ByteString): Long
expect abstract fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long

Returns the first index in this buffer that is at or after fromIndex and that contains any of the bytes in targetBytes. This expands the buffer as necessary until a target byte is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.

actual abstract fun indexOfElement(targetBytes: ByteString): Long
actual abstract fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long
actual abstract fun indexOfElement(targetBytes: ByteString): Long
actual abstract fun indexOfElement(targetBytes: ByteString, fromIndex: Long): Long
Link copied to clipboard
inline fun Source.inflate(inflater: Inflater = Inflater()): InflaterSource

Returns an InflaterSource that DEFLATE-decompresses this Source while reading.

Link copied to clipboard
abstract fun inputStream(): InputStream

Returns an input stream that reads from this source.

Link copied to clipboard
abstract fun isOpen(): Boolean
Link copied to clipboard
expect abstract fun peek(): BufferedSource

Returns a new BufferedSource that can read data from this BufferedSource without consuming it. The returned source becomes invalid once this source is next read or closed.

actual abstract fun peek(): BufferedSource
actual abstract fun peek(): BufferedSource
Link copied to clipboard
expect abstract fun rangeEquals(offset: Long, bytes: ByteString): Boolean

Returns true if the bytes at offset in this source equal bytes. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.

expect abstract fun rangeEquals(offset: Long, bytes: ByteString, bytesOffset: Int, byteCount: Int): Boolean

Returns true if byteCount bytes at offset in this source equal bytes at bytesOffset. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.

actual abstract fun rangeEquals(offset: Long, bytes: ByteString): Boolean
actual abstract fun rangeEquals(offset: Long, bytes: ByteString, bytesOffset: Int, byteCount: Int): Boolean
actual abstract fun rangeEquals(offset: Long, bytes: ByteString): Boolean
actual abstract fun rangeEquals(offset: Long, bytes: ByteString, bytesOffset: Int, byteCount: Int): Boolean
read
Link copied to clipboard
expect abstract fun read(sink: ByteArray): Int

Removes up to sink.length bytes from this and copies them into sink. Returns the number of bytes read, or -1 if this source is exhausted.

expect abstract fun read(sink: ByteArray, offset: Int, byteCount: Int): Int

Removes up to byteCount bytes from this and copies them into sink at offset. Returns the number of bytes read, or -1 if this source is exhausted.

abstract fun read(sink: Buffer, byteCount: Long): Long

Removes at least 1, and up to byteCount bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

abstract fun read(p0: ByteBuffer): Int
actual abstract fun read(sink: ByteArray): Int
actual abstract fun read(sink: ByteArray, offset: Int, byteCount: Int): Int

abstract fun read(sink: Buffer, byteCount: Long): Long

Removes at least 1, and up to byteCount bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

actual abstract fun read(sink: ByteArray): Int
actual abstract fun read(sink: ByteArray, offset: Int, byteCount: Int): Int
abstract fun read(sink: Buffer, byteCount: Long): Long

Removes at least 1, and up to byteCount bytes from this and appends them to sink. Returns the number of bytes read, or -1 if this source is exhausted.

Link copied to clipboard
expect abstract fun readAll(sink: Sink): Long

Removes all bytes from this and appends them to sink. Returns the total number of bytes written to sink which will be 0 if this is exhausted.

actual abstract fun readAll(sink: Sink): Long
actual abstract fun readAll(sink: Sink): Long
Link copied to clipboard
expect abstract fun readByte(): Byte

Removes a byte from this source and returns it.

actual abstract fun readByte(): Byte
actual abstract fun readByte(): Byte
Link copied to clipboard
expect abstract fun readByteArray(): ByteArray

Removes all bytes from this and returns them as a byte array.

expect abstract fun readByteArray(byteCount: Long): ByteArray

Removes byteCount bytes from this and returns them as a byte array.

actual abstract fun readByteArray(): ByteArray
actual abstract fun readByteArray(byteCount: Long): ByteArray
actual abstract fun readByteArray(): ByteArray
actual abstract fun readByteArray(byteCount: Long): ByteArray
Link copied to clipboard
expect abstract fun readByteString(): ByteString

Removes all bytes from this and returns them as a byte string.

expect abstract fun readByteString(byteCount: Long): ByteString

Removes byteCount bytes from this and returns them as a byte string.

actual abstract fun readByteString(): ByteString
actual abstract fun readByteString(byteCount: Long): ByteString
actual abstract fun readByteString(): ByteString
actual abstract fun readByteString(byteCount: Long): ByteString
Link copied to clipboard
expect abstract fun readDecimalLong(): Long

Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading '-'). This will iterate until a non-digit character is found.

actual abstract fun readDecimalLong(): Long
actual abstract fun readDecimalLong(): Long
Link copied to clipboard
expect abstract fun readFully(sink: ByteArray)

Removes exactly sink.length bytes from this and copies them into sink. Throws an java.io.EOFException if the requested number of bytes cannot be read.

expect abstract fun readFully(sink: Buffer, byteCount: Long)

Removes exactly byteCount bytes from this and appends them to sink. Throws an java.io.EOFException if the requested number of bytes cannot be read.

actual abstract fun readFully(sink: ByteArray)
actual abstract fun readFully(sink: Buffer, byteCount: Long)
actual abstract fun readFully(sink: ByteArray)
actual abstract fun readFully(sink: Buffer, byteCount: Long)
Link copied to clipboard
expect abstract fun readHexadecimalUnsignedLong(): Long

Reads a long form this source in hexadecimal form (i.e., as a string in base 16). This will iterate until a non-hexadecimal character is found.

actual abstract fun readHexadecimalUnsignedLong(): Long
actual abstract fun readHexadecimalUnsignedLong(): Long
Link copied to clipboard
expect abstract fun readInt(): Int

Removes four bytes from this source and returns a big-endian int.

actual abstract fun readInt(): Int
actual abstract fun readInt(): Int
Link copied to clipboard
expect abstract fun readIntLe(): Int

Removes four bytes from this source and returns a little-endian int.

actual abstract fun readIntLe(): Int
actual abstract fun readIntLe(): Int
Link copied to clipboard
expect abstract fun readLong(): Long

Removes eight bytes from this source and returns a big-endian long.

actual abstract fun readLong(): Long
actual abstract fun readLong(): Long
Link copied to clipboard
expect abstract fun readLongLe(): Long

Removes eight bytes from this source and returns a little-endian long.

actual abstract fun readLongLe(): Long
actual abstract fun readLongLe(): Long
Link copied to clipboard
expect abstract fun readShort(): Short

Removes two bytes from this source and returns a big-endian short.

actual abstract fun readShort(): Short
actual abstract fun readShort(): Short
Link copied to clipboard
expect abstract fun readShortLe(): Short

Removes two bytes from this source and returns a little-endian short.

actual abstract fun readShortLe(): Short
actual abstract fun readShortLe(): Short
Link copied to clipboard
abstract fun readString(charset: Charset): String

Removes all bytes from this, decodes them as charset, and returns the string.

abstract fun readString(byteCount: Long, charset: Charset): String

Removes byteCount bytes from this, decodes them as charset, and returns the string.

Link copied to clipboard
expect abstract fun readUtf8(): String

Removes all bytes from this, decodes them as UTF-8, and returns the string. Returns the empty string if this source is empty.

expect abstract fun readUtf8(byteCount: Long): String

Removes byteCount bytes from this, decodes them as UTF-8, and returns the string.

actual abstract fun readUtf8(): String
actual abstract fun readUtf8(byteCount: Long): String
actual abstract fun readUtf8(): String
actual abstract fun readUtf8(byteCount: Long): String
Link copied to clipboard
expect abstract fun readUtf8CodePoint(): Int

Removes and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.

actual abstract fun readUtf8CodePoint(): Int
actual abstract fun readUtf8CodePoint(): Int
Link copied to clipboard
expect abstract fun readUtf8Line(): String?

Removes and returns characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.

actual abstract fun readUtf8Line(): String?
actual abstract fun readUtf8Line(): String?
Link copied to clipboard
expect abstract fun readUtf8LineStrict(): String

Removes and returns characters up to but not including the next line break. A line break is either "\n" or "\r\n"; these characters are not included in the result.

expect abstract fun readUtf8LineStrict(limit: Long): String

Like readUtf8LineStrict, except this allows the caller to specify the longest allowed match. Use this to protect against streams that may not include "\n" or "\r\n".

actual abstract fun readUtf8LineStrict(): String
actual abstract fun readUtf8LineStrict(limit: Long): String
actual abstract fun readUtf8LineStrict(): String
actual abstract fun readUtf8LineStrict(limit: Long): String
Link copied to clipboard
expect abstract fun request(byteCount: Long): Boolean

Returns true when the buffer contains at least byteCount bytes, expanding it as necessary. Returns false if the source is exhausted before the requested bytes can be read.

actual abstract fun request(byteCount: Long): Boolean
actual abstract fun request(byteCount: Long): Boolean
Link copied to clipboard
expect abstract fun require(byteCount: Long)

Returns when the buffer contains at least byteCount bytes. Throws an java.io.EOFException if the source is exhausted before the required bytes can be read.

actual abstract fun require(byteCount: Long)
actual abstract fun require(byteCount: Long)
Link copied to clipboard
expect abstract fun select(options: Options): Int

Finds the first byte string in options that is a prefix of this buffer, consumes it from this source, and returns its index. If no byte string in options is a prefix of this buffer this returns -1 and no bytes are consumed.

expect abstract fun <T : Any> select(options: TypedOptions<T>): T?

Finds the first item in options whose encoding is a prefix of this buffer, consumes it from this buffer, and returns it. If no item in options is a prefix of this source, this function returns null and no bytes are consumed.

actual abstract fun select(options: Options): Int
actual abstract fun <T : Any> select(options: TypedOptions<T>): T?
actual abstract fun select(options: Options): Int
actual abstract fun <T : Any> select(options: TypedOptions<T>): T?
Link copied to clipboard
expect abstract fun skip(byteCount: Long)

Reads and discards byteCount bytes from this source. Throws an java.io.EOFException if the source is exhausted before the requested bytes can be skipped.

actual abstract fun skip(byteCount: Long)
actual abstract fun skip(byteCount: Long)
timeout
Link copied to clipboard
abstract fun timeout(): Timeout

Returns the timeout for this source.

abstract fun timeout(): Timeout

Returns the timeout for this source.

abstract fun timeout(): Timeout

Returns the timeout for this source.