RFR: 8272297: FileInputStream should override transferTo() for better performance [v3]

Alan Bateman alanb at openjdk.java.net
Fri Aug 13 18:44:24 UTC 2021


On Fri, 13 Aug 2021 14:53:45 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Please consider this request to add an override `java.io.FileInputStream.transferTo(OutputStream)` with improved performance if the parameter is a `FileOutputStream`.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8272297: Improve growing source and partial transfer cases

src/java.base/share/classes/java/io/FileInputStream.java line 367:

> 365:             long count = fc.size() - pos;
> 366:             if (pos >= 0 && count >= 0) {
> 367:                 transferred = fc.transferTo(pos, Long.MAX_VALUE, fos.getChannel());

This version looks better I think we can drop L365 and 366. The position cannot be negative and checking that size >= pos isn't useful. In other words, you can just call transferTo with the position without these checks.

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

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


More information about the core-libs-dev mailing list