RFR: 4619075: (ch) newChannel() should return Gathering/ScatteringByteChannel [v3]

Alan Bateman alanb at openjdk.java.net
Tue Oct 19 06:56:52 UTC 2021


On Wed, 13 Oct 2021 21:05:26 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Modify `Channels.newChannel(InputStream)` and `Channels.newChannel(OutputStream)` to return `ScatteringByteChannel` and `GatheringByteChannel`, respectively.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   4619075: Add @since tags to new methods

src/java.base/share/classes/java/nio/channels/Channels.java line 378:

> 376:             long totalBytesRead = 0L;
> 377:             int maxIndex = offset + length;
> 378:             for (int i = offset; i < maxIndex; i++) {

There are a few problems with this loop. If the second/subsequent buffer is ready only then it will throw IllegalArgumentException after reading bytes into the first buffer. It also doesn't happen cases where there are I/O exceptions thrown after some bytes have been read.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5922


More information about the nio-dev mailing list