Byte iterator only available for buffered input streams,

InputStream.buffered() returns BufferedInputStream.
This commit is contained in:
Ilya Gorbunov
2015-11-23 15:29:42 +03:00
parent c848ebdc52
commit 229504f42d
2 changed files with 4 additions and 5 deletions
+3 -4
View File
@@ -6,9 +6,8 @@ import java.io.*
import java.nio.charset.Charset
import java.util.NoSuchElementException
/** Returns an [Iterator] of bytes in this input stream. */
@Deprecated("It's not recommended to iterate through input stream bytes")
public fun InputStream.iterator(): ByteIterator =
/** Returns an [Iterator] of bytes read from this input stream. */
public operator fun BufferedInputStream.iterator(): ByteIterator =
object : ByteIterator() {
var nextByte = -1
@@ -60,7 +59,7 @@ public fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStrea
* Creates a buffered input stream wrapping this stream.
* @param bufferSize the buffer size to use.
*/
public fun InputStream.buffered(bufferSize: Int = defaultBufferSize): InputStream
public fun InputStream.buffered(bufferSize: Int = defaultBufferSize): BufferedInputStream
= if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
+1 -1
View File
@@ -25,7 +25,7 @@ class OldStdlibTest() {
x [index] = index.toByte()
}
x.inputStream().use { stream ->
x.inputStream().buffered().use { stream ->
for(b in stream) {
println(b)
}