Move ByteArray.inputStream() method from kotlin package to kotlin.io

This commit is contained in:
Ilya Gorbunov
2015-09-24 22:30:24 +03:00
parent 8de40c01b9
commit 379c39a2ef
3 changed files with 22 additions and 4 deletions
@@ -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)
/**
@@ -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.
+5 -3
View File
@@ -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)
}
}
}
}