Introduce JVM readln() and readlnOrNull() top-level functions #KT-48456

This commit is contained in:
Abduqodiri Qurbonzoda
2021-09-02 01:18:16 +03:00
committed by Space
parent 0d58bb14b2
commit 91aa956f34
2 changed files with 26 additions and 0 deletions
@@ -140,6 +140,30 @@ public actual inline fun println() {
System.out.println()
}
/**
* Reads a line of input from the standard input stream and returns it,
* or throws a [RuntimeException] if EOF has already been reached when [readln] is called.
*
* LF or CRLF is treated as the line terminator. Line terminator is not included in the returned string.
*
* The input is decoded using the system default Charset. A [CharacterCodingException] is thrown if input is malformed.
*/
@SinceKotlin("1.6")
public fun readln(): String = readlnOrNull() ?: throw ReadAfterEOFException("EOF has already been reached")
/**
* Reads a line of input from the standard input stream and returns it,
* or return `null` if EOF has already been reached when [readlnOrNull] is called.
*
* LF or CRLF is treated as the line terminator. Line terminator is not included in the returned string.
*
* The input is decoded using the system default Charset. A [CharacterCodingException] is thrown if input is malformed.
*/
@SinceKotlin("1.6")
public fun readlnOrNull(): String? = readLine()
private class ReadAfterEOFException(message: String?) : RuntimeException(message)
/**
* Reads a line of input from the standard input stream.
*
@@ -3098,6 +3098,8 @@ public final class kotlin/io/CloseableKt {
public final class kotlin/io/ConsoleKt {
public static final fun readLine ()Ljava/lang/String;
public static final fun readln ()Ljava/lang/String;
public static final fun readlnOrNull ()Ljava/lang/String;
}
public final class kotlin/io/ConstantsKt {