From 0eba06405aa9d4288bef8fc2e005ee2e46ac634a Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 21 Nov 2016 21:44:37 +0300 Subject: [PATCH] Use InputStream as another guess for estimated size in InputStream.readBytes() --- libraries/stdlib/src/kotlin/io/IOStreams.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/stdlib/src/kotlin/io/IOStreams.kt b/libraries/stdlib/src/kotlin/io/IOStreams.kt index 4fcee1c1dd8..74121ac26b0 100644 --- a/libraries/stdlib/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/src/kotlin/io/IOStreams.kt @@ -113,7 +113,7 @@ public fun InputStream.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFE * **Note**: It is the caller's responsibility to close this stream. */ public fun InputStream.readBytes(estimatedSize: Int = DEFAULT_BUFFER_SIZE): ByteArray { - val buffer = ByteArrayOutputStream(estimatedSize) + val buffer = ByteArrayOutputStream(Math.max(estimatedSize, this.available())) copyTo(buffer) return buffer.toByteArray() }