Skip to content

okio / okio / BufferedSource / indexOfElement

indexOfElement

(js, jvm, native) abstract fun indexOfElement(targetBytes:ByteString):Long

Equivalent to indexOfElement(targetBytes, 0).

(js, jvm, native) 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.

ByteString ANY_VOWEL = ByteString.encodeUtf8("AEOIUaeoiu");

Buffer buffer = new Buffer();
buffer.writeUtf8("Dr. Alan Grant");

assertEquals(4,  buffer.indexOfElement(ANY_VOWEL));    // 'A' in 'Alan'.
assertEquals(11, buffer.indexOfElement(ANY_VOWEL, 9)); // 'a' in 'Grant'.