readLineStrict
Removes and returns UTF-8 encoded characters up to but not including the next line break, throwing EOFException if a line break was not encountered. A line break is either "\n"
or "\r\n"
; these characters are not included in the result.
The returned string will have at most limit UTF-8 bytes, and the maximum number of bytes scanned is limit + 2
. If limit == 0
this will always throw an EOFException because no bytes will be scanned.
No bytes are discarded if the match fails.
Parameters
limit
the maximum UTF-8 bytes constituting a returned string.
Throws
when the source does not contain a string consisting with at most limit bytes followed by line break characters.
when the source is closed.
when limit is negative.
Samples
import kotlinx.io.*
import kotlin.test.*
fun main() {
//sampleStart
val buffer = Buffer()
buffer.writeString("No new line here.")
assertFailsWith<EOFException> { buffer.readLineStrict() }
assertEquals("No new line here.", buffer.readLine())
buffer.writeString("Line1\n\nLine2")
assertEquals("Line1", buffer.readLineStrict())
assertEquals("\nLine2", buffer.readString())
//sampleEnd
}