Use InputStream as another guess for estimated size in InputStream.readBytes()

This commit is contained in:
Ilya Gorbunov
2016-11-21 21:44:37 +03:00
parent e41cbe6fe1
commit 0eba06405a
+1 -1
View File
@@ -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()
}