On Thu, 12 Aug 2021 21:07:53 GMT, Brian Burkhalter <b...@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: Set source position after FC.transferTo(); add test

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

> 362:             FileChannel fci = getChannel();
> 363:             long pos = fci.position();
> 364:             long count = fci.size() - pos;

It might be better to just specify the count as Long.MAX_VALUE and test the 
size after the transfer. This would be a bit more robust in the scenario that 
the file grows and would avoid fallback when the file is truncated, e.g.

FileChannel fc = getChannel();
long pos = fc.position();
long transferred = fc.transferTo(pos, Long.MAX_VALUE, out.getChannel());
long newPos = pos + transferred;
fc.position(newPos);
if (newPos >= fc.size()) {
    return transferred;
}

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

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

Reply via email to