diff --git a/libraries/stdlib/src/kotlin/io/IOStreams.kt b/libraries/stdlib/src/kotlin/io/IOStreams.kt index be45068c749..b9f0a586a5c 100644 --- a/libraries/stdlib/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/src/kotlin/io/IOStreams.kt @@ -41,6 +41,10 @@ public fun InputStream.iterator(): ByteIterator = } } + +/** Creates a new byte input stream for the string. */ +public fun String.byteInputStream(charset: Charset = Charsets.UTF_8): InputStream = ByteArrayInputStream(toByteArray(charset)) + /** * Creates a buffered input stream wrapping this stream. * @param bufferSize the buffer size to use. diff --git a/libraries/stdlib/src/kotlin/io/ReadWrite.kt b/libraries/stdlib/src/kotlin/io/ReadWrite.kt index e80804abc26..64592def5e9 100644 --- a/libraries/stdlib/src/kotlin/io/ReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/ReadWrite.kt @@ -31,6 +31,9 @@ public fun Reader.forEachLine(block: (String) -> Unit): Unit = useLines { it.for public inline fun Reader.useLines(block: (Sequence) -> T): T = buffered().use { block(it.lineSequence()) } +/** Creates a new reader for the string. */ +public fun String.reader(): StringReader = StringReader(this) + /** * Returns a sequence of corresponding file lines. * @@ -139,6 +142,7 @@ public fun URL.readText(charset: Charset = Charsets.UTF_8): String = readBytes() */ public fun URL.readBytes(): ByteArray = openStream().use { it.readBytes() } +// TODO: Move to kotlin package, rename to using /** * Executes the given [block] function on this resource and then closes it down correctly whether an exception * is thrown or not. diff --git a/libraries/stdlib/src/kotlin/io/files/Utils.kt b/libraries/stdlib/src/kotlin/io/files/Utils.kt index 6da25880364..444a259ff7b 100644 --- a/libraries/stdlib/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/src/kotlin/io/files/Utils.kt @@ -115,12 +115,6 @@ public fun String.allSeparatorsToSystem(): String { return separatorsToSystem().pathSeparatorsToSystem() } -/** Creates a new reader for the string. */ -public fun String.reader(): StringReader = StringReader(this) - -/** Creates a new byte input stream for the string. */ -public fun String.byteInputStream(charset: Charset = Charsets.UTF_8): InputStream = ByteArrayInputStream(toByteArray(charset)) - /** * Returns a pathname of this file with all path separators replaced with File.pathSeparator. *