Relax writeText/appendText parameter type to CharSequence

KT-19192
This commit is contained in:
Ilya Gorbunov
2020-11-20 04:55:56 +03:00
parent 2ee8bf7dde
commit 64d85f259c
3 changed files with 10 additions and 10 deletions
@@ -157,8 +157,8 @@ public fun Path.readText(charset: Charset = Charsets.UTF_8): String =
*/
@SinceKotlin("1.4")
@ExperimentalPathApi
public fun Path.writeText(text: String, charset: Charset = Charsets.UTF_8, vararg options: OpenOption) {
Files.newOutputStream(this, *options).writer(charset).use { it.write(text) }
public fun Path.writeText(text: CharSequence, charset: Charset = Charsets.UTF_8, vararg options: OpenOption) {
Files.newOutputStream(this, *options).writer(charset).use { it.append(text) }
}
/**
@@ -169,8 +169,8 @@ public fun Path.writeText(text: String, charset: Charset = Charsets.UTF_8, varar
*/
@SinceKotlin("1.4")
@ExperimentalPathApi
public fun Path.appendText(text: String, charset: Charset = Charsets.UTF_8) {
Files.newOutputStream(this, StandardOpenOption.APPEND).writer(charset).use { it.write(text) }
public fun Path.appendText(text: CharSequence, charset: Charset = Charsets.UTF_8) {
Files.newOutputStream(this, StandardOpenOption.APPEND).writer(charset).use { it.append(text) }
}
/**
@@ -15,8 +15,8 @@ class PathReadWriteTest : AbstractPathTest() {
fun appendText() {
val file = createTempFile().cleanup()
file.writeText("Hello\n")
file.appendText("World\n")
file.writeText("Again", Charsets.US_ASCII, StandardOpenOption.APPEND)
file.appendText("World\n" as CharSequence)
file.writeText(StringBuilder("Again"), Charsets.US_ASCII, StandardOpenOption.APPEND)
assertEquals("Hello\nWorld\nAgain", file.readText())
assertEquals(listOf("Hello", "World", "Again"), file.readLines(Charsets.UTF_8))