RFR: 8278268 - (ch) InputStream returned by Channels.newInputStream should have fast path for FileChannel targets [v7]

Alan Bateman alanb at openjdk.java.net
Mon Dec 13 16:53:09 UTC 2021


On Sun, 12 Dec 2021 14:37:35 GMT, Markus KARG <duke at openjdk.java.net> wrote:

>> This sub-issue defines the work to be done to implement JDK-8265891 solely for the particular case of FileChannel.transferFrom(ReadableByteChannel), including special treatment of SelectableByteChannel.
>
> Markus KARG has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Simplified using checked function
>    
>    Signed-off-by: Markus Karg <markus at headcrashing.eu>
>  - Common implementation for all 2 GB tests
>    
>    Signed-off-by: Markus Karg <markus at headcrashing.eu>

src/java.base/share/classes/sun/nio/ch/ChannelInputStream.java line 301:

> 299:                     }
> 300:                     bb.clear();
> 301:                     pos += bytesRead;

I've been busy so only getting to this PR now.

Since we are guaranteed that src is configured blocking then the only remaining reason for transferFrom to return 0 is when EOF is reached. Can we drop the temporary buffer and just replace the buffer in the block with:

            long n;
            while ((n = dst.transferFrom(src, pos, Long.MAX_VALUE)) > 0) {
                pos += n;
            }

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

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


More information about the nio-dev mailing list