readLineStrict

suspend fun ByteReadChannel.readLineStrict(limit: Long = Long.MAX_VALUE, lineEnding: LineEnding = LineEnding.Default): String?(source)

Reads and returns a line of UTF-8 characters. 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 even if it fails to complete.

Report a problem

Return

the line, or null if can't read from the channel

Parameters

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