Deprecate readBytes with estimatedSize parameter, add overload without parameters

Add a test for readBytes.

#KT-19305 Fixed
This commit is contained in:
Ilya Gorbunov
2018-08-06 22:22:53 +03:00
parent cbc92bc9a1
commit 17e04b2665
3 changed files with 38 additions and 1 deletions
@@ -117,8 +117,22 @@ public fun InputStream.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFE
*
* **Note**: It is the caller's responsibility to close this stream.
*/
@Deprecated("Use readBytes() overload without estimatedSize parameter", ReplaceWith("readBytes()"))
// TODO: Add DeprecatedSince when available
public fun InputStream.readBytes(estimatedSize: Int = DEFAULT_BUFFER_SIZE): ByteArray {
val buffer = ByteArrayOutputStream(Math.max(estimatedSize, this.available()))
val buffer = ByteArrayOutputStream(maxOf(estimatedSize, this.available()))
copyTo(buffer)
return buffer.toByteArray()
}
/**
* Reads this stream completely into a byte array.
*
* **Note**: It is the caller's responsibility to close this stream.
*/
@SinceKotlin("1.3")
public fun InputStream.readBytes(): ByteArray {
val buffer = ByteArrayOutputStream(maxOf(DEFAULT_BUFFER_SIZE, this.available()))
copyTo(buffer)
return buffer.toByteArray()
}