File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1655,7 +1655,7 @@ internal open class ByteBufferChannel(
16551655 }
16561656
16571657 if (! read) {
1658- if (isClosedForRead) {
1658+ if (isClosedForRead && min > 0 ) {
16591659 throw EOFException (" Got EOF but at least $min bytes were expected" )
16601660 }
16611661
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ import java.nio.*
55import java.nio.channels.*
66
77/* *
8- * Copy up to [limit] bytes to blocking NIO [channel]. Copying to non-blocking channel requires selection and
9- * not supported. It does suspend if no data available in byte channel but may block if destination NIO channel blocks.
8+ * Copy up to [limit] bytes to blocking NIO [channel].
9+ * Copying to a non-blocking channel requires selection and not supported.
10+ * It is suspended if no data are available in a byte channel but may block if destination NIO channel blocks.
1011 *
1112 * @return number of bytes copied
1213 */
Original file line number Diff line number Diff line change @@ -253,4 +253,19 @@ class ByteBufferChannelTest {
253253 reader.await()
254254 writer.join()
255255 }
256+
257+ @Test
258+ fun testReadWithNoMinDoesntThrow () = runBlocking {
259+ val channel = ByteChannel (true )
260+
261+ channel.writeByte(1 )
262+ channel.read(0 ) {
263+ assertEquals(1 , it.remaining())
264+ it.get()
265+ }
266+ channel.close()
267+ channel.read(0 ) {
268+ assertEquals(0 , it.remaining())
269+ }
270+ }
256271}
You can’t perform that action at this time.
0 commit comments