indexOf

fun Buffer.indexOf(byte: Byte, startIndex: Long = 0, endIndex: Long = size): Long(source)

Returns an index of byte first occurrence in the range of startIndex to endIndex, or -1 when the range doesn't contain byte.

The scan terminates at either endIndex or buffers' exhaustion, whichever comes first.

Parameters

byte

the value to find.

startIndex

the start of the range (inclusive) to find byte, 0 by default.

endIndex

the end of the range (exclusive) to find byte, Buffer.size by default.

Throws

when the source is closed.

when startIndex > endIndex or either of indices is negative.

Samples


fun Source.indexOf(byteString: ByteString, startIndex: Long = 0): Long(source)

Returns the index of the first match for byteString in the source at or after startIndex. This expands the source's buffer as necessary until byteString 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.

For empty byte strings this function returns startIndex if it lays within underlying buffer's bounds, 0 if startIndex was negative and the size of the underlying buffer if startIndex exceeds its size. If the startIndex value was greater than the underlying buffer's size, the data will be fetched and buffered despite the byteString is empty.

Parameters

byteString

the sequence of bytes to find within the source.

startIndex

the index into the source to start searching from.

Throws

if the source is closed.

when some I/O error occurs.

Samples


fun Buffer.indexOf(byteString: ByteString, startIndex: Long = 0): Long(source)

Returns the index of the first match for byteString in the buffer at or after startIndex.

For empty byte strings this function returns startIndex if it lays within buffer's bounds, 0 if startIndex was negative and Buffer.size if it was greater or equal to Buffer.size.

Parameters

byteString

the sequence of bytes to find within the buffer.

startIndex

the index into the buffer to start searching from.

Samples


fun Source.indexOf(byte: Byte, startIndex: Long = 0, endIndex: Long = Long.MAX_VALUE): Long(source)

Returns an index of byte first occurrence in the range of startIndex to endIndex, or -1 when the range doesn't contain byte.

The scan terminates at either endIndex or source's exhaustion, whichever comes first. The maximum number of bytes scanned is toIndex-fromIndex. If byte not found in buffered data, endIndex is yet to be reached and the underlying source is not yet exhausted then new data will be read from the underlying source into the buffer.

Parameters

byte

the value to find.

startIndex

the start of the range (inclusive) to find byte, 0 by default.

endIndex

the end of the range (exclusive) to find byte, Long.MAX_VALUE by default.

Throws

when the source is closed.

when startIndex > endIndex or either of indices is negative.

when some I/O error occurs.

Samples