writeFromSequence

fun writeFromSequence(characters: CharSequence, startIndex: Int, endIndex: Int)(source)

Encodes all the characters in a specific range of a CharSequence and writes them to the sink's underlying destination.

This method does not write the 2-byte "UTF length" that comes before standard Modified UTF-8 strings. That must be written separately if needed.

The "range" is defined as a startIndex and endIndex, which behave the same as the first and second operands of Kotlin's infix until function. Both indexes must be at least 0, and the startIndex cannot be greater than the endIndex, though they can be equal to select 0 characters. startIndex must be less than the sequence's length and endIndex must be less than or equal to length. If the above conditions are not met, an IllegalArgumentException is thrown.

Parameters

characters

The sequence of characters to write from.

startIndex

The first and lowest index from which characters will be written.

endIndex

The index after startIndex to stop writing the characters at.

This index is exclusive, meaning the character at this index will not be written, nor will any after it.

Throws

if the mutf8Length of the characters in that range exceeds 65535 (UShort.MAX_VALUE).

if an I/O issue occurs while trying to write any or all of the sequence's encoded bytes.


fun writeFromSequence(characters: CharSequence, range: IntRange)(source)

An alias for writeFromSequence that uses a single range parameter, rather than a separate startIndex and endIndex.

Other than that, the entire contract of writeFromSequence applies to this method as well.

See also


Encodes all the characters in a CharSequence and writes them to the sink's underlying destination.

This is an alias for writeFromSequence with startIndex = 0 and endIndex = characters.length. The selected indices are guaranteed to be valid, so all IllegalArgumentExceptions documented at writeFromSequence are guaranteed not to occur unless also documented on this function. Other than that, the contract & documentation for writeFromSequence applies here as well.

See also

Throws