Change default buffer size to be 8K (same default as in java BufferedReader).

Rename internal constants.
This commit is contained in:
Ilya Gorbunov
2016-02-04 20:13:12 +03:00
parent faba229b11
commit 17a95384e1
2 changed files with 5 additions and 6 deletions
+3 -4
View File
@@ -5,14 +5,13 @@ package kotlin.io
/**
* Returns the default buffer size when working with buffered streams.
*/
public const val DEFAULT_BUFFER_SIZE: Int = 64 * 1024
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024
/**
* Returns the default block size for forEachBlock().
*/
internal const val defaultBlockSize: Int = 4096
internal const val DEFAULT_BLOCK_SIZE: Int = 4096
/**
* Returns the minimum block size for forEachBlock().
*/
internal const val minimumBlockSize: Int = 512
internal const val MINIMUM_BLOCK_SIZE: Int = 512
@@ -102,7 +102,7 @@ public fun File.appendText(text: String, charset: Charset = Charsets.UTF_8): Uni
*
* @param action function to process file blocks.
*/
public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBlock(defaultBlockSize, action)
public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBlock(DEFAULT_BLOCK_SIZE, action)
/**
* Reads file by byte blocks and calls [action] for each block read.
@@ -114,7 +114,7 @@ public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBl
* @param blockSize size of a block, replaced by 512 if it's less, 4096 by default.
*/
public fun File.forEachBlock(blockSize: Int, action: (ByteArray, Int) -> Unit): Unit {
val arr = ByteArray(if (blockSize < minimumBlockSize) minimumBlockSize else blockSize)
val arr = ByteArray(blockSize.coerceAtLeast(MINIMUM_BLOCK_SIZE))
val fis = FileInputStream(this)
try {