readUTF8LineTo
Deprecated
Use readLineStrictTo or readLineTo instead. See deprecation notes for more details.
Reads a line of UTF-8 characters to the specified out buffer. It recognizes CR, LF, and CRLF as a line delimiter.
Deprecation
This function is deprecated. Use readLineStrictTo or readLineTo instead.
Use readLineStrictTo when:
You need to limit the line length and throw TooLongLineException when the limit is reached.
You expect an explicit line break at the end of a line. EOFException will be thrown when the channel is closed before the line break.
Use readLineTo when:
You do not need to limit line length.
An explicit line break at the end of the channel is not mandatory.
Compared to readUTF8LineTo, the new functions differ in the following ways:
They recognize LF and CRLF as line delimiters by default, which provides better performance. To keep current behavior and recognize all line delimiters (CR, LF, and CRLF), specify LineEnding.Lenient.
They return the return number of appended characters instead, or
-1if the channel is empty, instead of returning Boolean.readLineStrictTo accepts Long instead of Int as a limit parameter.
The direct equivalent of readUTF8LineTo would be:
// Before
val success = channel.readUTF8LineTo(out, max = 1024)
// After
val success = try {
channel.readLineStrictTo(out, limit = 1024, lineEnding = LineEnding.Lenient) >= 0
} catch (_: EOFException) {
true
}However, we recommend using the default line ending behavior (LineEnding.Default) and do not ignore unexpected end-of-input:
val success = channel.readLineTo(out, limit = 1024) >= 0Return
true if a new line separator was found or max bytes appended. false if no new line separator and no bytes read.
Parameters
the buffer to write the line to
the maximum number of characters to read
Throws
if max is reached before encountering a newline or end of input
Deprecated
Use readLineStrictTo instead.
Reads a line of UTF-8 characters to the specified out buffer. It recognizes specified line endings as a line delimiter. By default, all line endings (CR, LF and CRLF) are allowed as a line delimiter.
Return
true if a new line separator was found or max bytes appended. false if no new line separator and no bytes read.
Parameters
the buffer to write the line to
the maximum number of characters to read
the allowed line endings
Throws
if max is reached before encountering a newline or end of input