diff --git a/libraries/stdlib/src/kotlin/io/Constants.kt b/libraries/stdlib/src/kotlin/io/Constants.kt index 2832a0fca2b..23b37de5fa1 100644 --- a/libraries/stdlib/src/kotlin/io/Constants.kt +++ b/libraries/stdlib/src/kotlin/io/Constants.kt @@ -6,7 +6,10 @@ package kotlin.io /** * Returns the default buffer size when working with buffered streams. */ -public val defaultBufferSize: Int = 64 * 1024 +public val DEFAULT_BUFFER_SIZE: Int = 64 * 1024 + +@Deprecated("Use DEFAULT_BUFFER_SIZE constant instead.", ReplaceWith("kotlin.io.DEFAULT_BUFFER_SIZE")) +public val defaultBufferSize: Int = DEFAULT_BUFFER_SIZE /** * Returns the default block size for forEachBlock(). diff --git a/libraries/stdlib/src/kotlin/io/IOStreams.kt b/libraries/stdlib/src/kotlin/io/IOStreams.kt index 60543659650..a8834a8e95c 100644 --- a/libraries/stdlib/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/src/kotlin/io/IOStreams.kt @@ -62,7 +62,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): BufferedInputStream +public fun InputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedInputStream = if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize) /** Creates a reader on this input stream using UTF-8 or the specified [charset]. */ @@ -83,7 +83,7 @@ public fun InputStream.bufferedReader(charset: String): BufferedReader = reader( * Creates a buffered output stream wrapping this stream. * @param bufferSize the buffer size to use. */ -public fun OutputStream.buffered(bufferSize: Int = defaultBufferSize): BufferedOutputStream +public fun OutputStream.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedOutputStream = if (this is BufferedOutputStream) this else BufferedOutputStream(this, bufferSize) /** Creates a writer on this output stream using UTF-8 or the specified [charset]. */ @@ -105,7 +105,7 @@ public fun OutputStream.bufferedWriter(charset: String): BufferedWriter = writer * * **Note** It is the caller's responsibility to close both of these resources. */ -public fun InputStream.copyTo(out: OutputStream, bufferSize: Int = defaultBufferSize): Long { +public fun InputStream.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long { var bytesCopied: Long = 0 val buffer = ByteArray(bufferSize) var bytes = read(buffer) @@ -122,7 +122,7 @@ public fun InputStream.copyTo(out: OutputStream, bufferSize: Int = defaultBuffer * * **Note**: It is the caller's responsibility to close this stream. */ -public fun InputStream.readBytes(estimatedSize: Int = defaultBufferSize): ByteArray { +public fun InputStream.readBytes(estimatedSize: Int = DEFAULT_BUFFER_SIZE): ByteArray { val buffer = ByteArrayOutputStream(estimatedSize) copyTo(buffer) return buffer.toByteArray() diff --git a/libraries/stdlib/src/kotlin/io/ReadWrite.kt b/libraries/stdlib/src/kotlin/io/ReadWrite.kt index cc667e6dcf5..23d47842d81 100644 --- a/libraries/stdlib/src/kotlin/io/ReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/ReadWrite.kt @@ -9,11 +9,11 @@ import java.util.NoSuchElementException /** Returns a buffered reader wrapping this Reader, or this Reader itself if it is already buffered. */ -public fun Reader.buffered(bufferSize: Int = defaultBufferSize): BufferedReader +public fun Reader.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedReader = if (this is BufferedReader) this else BufferedReader(this, bufferSize) /** Returns a buffered reader wrapping this Writer, or this Writer itself if it is already buffered. */ -public fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter +public fun Writer.buffered(bufferSize: Int = DEFAULT_BUFFER_SIZE): BufferedWriter = if (this is BufferedWriter) this else BufferedWriter(this, bufferSize) /** @@ -107,7 +107,7 @@ public fun Reader.readText(): String { * @param bufferSize size of character buffer to use in process. * @return number of bytes copies. */ -public fun Reader.copyTo(out: Writer, bufferSize: Int = defaultBufferSize): Long { +public fun Reader.copyTo(out: Writer, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long { var charsCopied: Long = 0 val buffer = CharArray(bufferSize) var chars = read(buffer) diff --git a/libraries/stdlib/src/kotlin/io/files/Utils.kt b/libraries/stdlib/src/kotlin/io/files/Utils.kt index a66160e4dd2..debdbecfbe5 100644 --- a/libraries/stdlib/src/kotlin/io/files/Utils.kt +++ b/libraries/stdlib/src/kotlin/io/files/Utils.kt @@ -262,7 +262,7 @@ public fun File.relativePath(descendant: File): String { * @throws FileAlreadyExistsException if the destination file already exists and 'rewrite' argument is set to `false`. * @throws IOException if any errors occur while copying. */ -public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = defaultBufferSize): Long { +public fun File.copyTo(dst: File, overwrite: Boolean = false, bufferSize: Int = DEFAULT_BUFFER_SIZE): Long { if (!exists()) { throw NoSuchFileException(file = this, reason = "The source file doesn't exist") } else if (isDirectory()) {