writeString

fun Sink.writeString(string: String, startIndex: Int = 0, endIndex: Int = string.length)(source)

Encodes the characters at startIndex up to endIndex from string in UTF-8 and writes it to this sink.

Parameters

string

the string to be encoded.

startIndex

the index (inclusive) of the first character to encode, 0 by default.

endIndex

the index (exclusive) of a character past to a last character to encode, string.length by default.

Throws

when startIndex or endIndex is out of range of string indices.

when startIndex > endIndex.

when the sink is closed.

when some I/O error occurs.

Samples


fun Sink.writeString(chars: CharSequence, startIndex: Int = 0, endIndex: Int = chars.length)(source)

Encodes the characters at startIndex up to endIndex from chars in UTF-8 and writes it to this sink.

Parameters

chars

the string to be encoded.

startIndex

the index (inclusive) of the first character to encode, 0 by default.

endIndex

the index (exclusive) of a character past to a last character to encode, chars.length by default.

Throws

when startIndex or endIndex is out of range of chars indices.

when startIndex > endIndex.

when the sink is closed.

when some I/O error occurs.

Samples

fun Sink.writeString(string: String, charset: Charset, startIndex: Int = 0, endIndex: Int = string.length)(source)

Encodes substring of string starting at startIndex and ending at endIndex using charset and writes into this sink.

Parameters

string

the string to encode into this sink.

charset

the Charset to use for encoding.

startIndex

the index of the first character to encode, inclusive, 0 by default.

endIndex

the index of the last character to encode, exclusive, string.length by default.

Throws

when startIndex or endIndex is out of range of string indices.

when startIndex > endIndex.

when the sink is closed.

when some I/O error occurs.

Samples