From 379c39a2ef554d2cd5baf80de865cf559b4278e0 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 24 Sep 2015 22:30:24 +0300 Subject: [PATCH] Move ByteArray.inputStream() method from kotlin package to kotlin.io --- libraries/stdlib/src/kotlin/collections/ArraysJVM.kt | 6 +++++- libraries/stdlib/src/kotlin/io/IOStreams.kt | 12 ++++++++++++ libraries/stdlib/test/OldStdlibTest.kt | 8 +++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt index d4d245e5242..0f904148d19 100644 --- a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt @@ -59,13 +59,15 @@ import kotlin.jvm.internal.Intrinsic /** * Creates an input stream for reading data from this byte array. */ -@Deprecated("Use inputStream() method instead.", ReplaceWith("this.inputStream()")) +@Deprecated("Use inputStream() method instead.", ReplaceWith("this.inputStream()", "kotlin.io.inputStream")) public val ByteArray.inputStream : ByteArrayInputStream get() = inputStream() /** * Creates an input stream for reading data from this byte array. */ +@Deprecated("Use inputStream() method from kotlin.io package instead.", ReplaceWith("this.inputStream()", "kotlin.io.inputStream")) +@HiddenDeclaration public fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInputStream(this) /** @@ -73,6 +75,8 @@ public fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInputStream( * @param offset the start offset of the portion of the array to read. * @param length the length of the portion of the array to read. */ +@Deprecated("Use inputStream() method from kotlin.io package instead.", ReplaceWith("this.inputStream(offset, length)", "kotlin.io.inputStream")) +@HiddenDeclaration public fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStream = ByteArrayInputStream(this, offset, length) /** diff --git a/libraries/stdlib/src/kotlin/io/IOStreams.kt b/libraries/stdlib/src/kotlin/io/IOStreams.kt index 669fcb1f18f..8d0e7aae6e2 100644 --- a/libraries/stdlib/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/src/kotlin/io/IOStreams.kt @@ -46,6 +46,18 @@ 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 an input stream for reading data from this byte array. + */ +public fun ByteArray.inputStream(): ByteArrayInputStream = ByteArrayInputStream(this) + +/** + * Creates an input stream for reading data from the specified portion of this byte array. + * @param offset the start offset of the portion of the array to read. + * @param length the length of the portion of the array to read. + */ +public fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStream = ByteArrayInputStream(this, offset, length) + /** * Creates a buffered input stream wrapping this stream. * @param bufferSize the buffer size to use. diff --git a/libraries/stdlib/test/OldStdlibTest.kt b/libraries/stdlib/test/OldStdlibTest.kt index fef64899d5b..1c934dbfdc0 100644 --- a/libraries/stdlib/test/OldStdlibTest.kt +++ b/libraries/stdlib/test/OldStdlibTest.kt @@ -9,7 +9,7 @@ import org.junit.Test as test class OldStdlibTest() { @test fun testCollectionEmpty() { - assertNot { + assertFalse { listOf(0, 1, 2).isEmpty() } } @@ -27,8 +27,10 @@ class OldStdlibTest() { x [index] = index.toByte() } - for(b in x.inputStream()) { - println(b) + x.inputStream().use { stream -> + for(b in stream) { + println(b) + } } } }