readLineStrictTo

suspend fun ByteReadChannel.readLineStrictTo(out: Appendable, limit: Long = Long.MAX_VALUE, lineEnding: LineEnding = LineEnding.Default): Long(source)

Reads a line of UTF-8 characters to the specified out buffer. Throws an exception if the line exceeds limit or doesn't end with a line break.

The limit counts characters after UTF-8 decoding, not bytes. Line break characters are not included in the result and not counted towards the limit. So this function may scan up to limit + 2 characters (when line ends with CRLF after limit).

Important: This function consumes bytes from the channel and appends them to out even if it fails to complete.

Report a problem

Return

number of characters appended to out, or -1 if can't read from the channel

Parameters

out

the buffer to append line to (line break characters are not appended)

limit

maximum characters to append to out. Unlimited by default.

lineEnding

line ending mode. Accepts LF and CRLF by default.

Throws

if the line exceeds limit

if the channel is closed before a line break is found