File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
commonMain/src/kotlinx/io
commonTest/src/kotlinx/io Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -151,11 +151,13 @@ public abstract class Input : Closeable {
151
151
* If no bytes are available in the input, [fill] method will be called directly on
152
152
* the [destination] buffer without an extra copy.
153
153
* Otherwise, available bytes are copied to the destination.
154
+ *
155
+ * @return number of bytes written in the [destination].
154
156
*/
155
157
public fun readAvailableTo (
156
158
destination : Buffer ,
157
159
startIndex : Int = 0,
158
- endIndex : Int = destination.size - startIndex
160
+ endIndex : Int = destination.size
159
161
): Int {
160
162
checkBufferAndIndexes(destination, startIndex, endIndex)
161
163
Original file line number Diff line number Diff line change
1
+ @file:Suppress(" FORBIDDEN_IDENTITY_EQUALS" )
1
2
package kotlinx.io
2
3
3
4
import kotlinx.io.buffer.*
@@ -138,6 +139,26 @@ class InputOutputTest {
138
139
assertArrayEquals(content.sliceArray(0 until size), output.toByteArray())
139
140
}
140
141
142
+ @Test
143
+ fun testReadAvailableToRange () {
144
+ var executed = false
145
+ val input: Input = object : Input () {
146
+ override fun fill (buffer : Buffer , startIndex : Int , endIndex : Int ): Int {
147
+ assertEquals(1024 , endIndex)
148
+ executed = true
149
+ return endIndex - startIndex
150
+ }
151
+
152
+ override fun closeSource () {
153
+ }
154
+
155
+ }
156
+ val buffer = bufferOf(ByteArray (1024 ))
157
+ val end = input.readAvailableTo(buffer, 1 )
158
+ assertTrue(executed)
159
+ assertEquals(1023 , end)
160
+ }
161
+
141
162
private fun checkException (block : () -> Unit ) {
142
163
var fail = false
143
164
try {
You can’t perform that action at this time.
0 commit comments