readLineStrict

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

Reads a UTF-8-encoded line and returns its decoded text. Throws an exception if the line exceeds limit or is not terminated by a line delimiter.

The limit counts bytes in the UTF-8-encoded line, not decoded characters. Line delimiter bytes are not included in the decoded line nor counted towards the limit. Therefore, this function may read up to limit + 2 bytes when the line ends with CRLF after limit bytes.

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

Report a problem

Return

the decoded line, or null if the channel is exhausted before a line can be read

Parameters

limit

the maximum number of bytes in the UTF-8-encoded line, excluding the line delimiter. Defaults to Long.MAX_VALUE.

lineEnding

line-ending mode. Accepts LF and CRLF by default.

Throws

if the line exceeds limit

if the channel is exhausted after reading line content but before a line delimiter is found