indexOf

common
abstract fun indexOf(b: Byte): Long

Equivalent to indexOf(b, 0).

abstract fun indexOf(b: Byte): Long
abstract fun indexOf(b: Byte, fromIndex: Long): Long
abstract fun indexOf(b: Byte, fromIndex: Long, toIndex: Long): Long
abstract fun indexOf(bytes: ByteString): Long
abstract fun indexOf(bytes: ByteString, fromIndex: Long): Long
common
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.

Buffer buffer = new Buffer();
buffer.writeUtf8("Don't move! He can't see us if we don't move.");

byte m = 'm';
assertEquals(6, buffer.indexOf(m));
assertEquals(40, buffer.indexOf(m, 12));
common
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.

The scan terminates at either toIndex or the end of the buffer, whichever comes first. The maximum number of bytes scanned is toIndex-fromIndex.

common
abstract fun indexOf(bytes: ByteString): Long

Equivalent to indexOf(bytes, 0).

common
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.

ByteString MOVE = ByteString.encodeUtf8("move");

Buffer buffer = new Buffer();
buffer.writeUtf8("Don't move! He can't see us if we don't move.");

assertEquals(6, buffer.indexOf(MOVE));
assertEquals(40, buffer.indexOf(MOVE, 12));