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

Brian Burkhalter bpb at openjdk.org
Wed Mar 1 01:40:15 UTC 2023


On Sat, 25 Feb 2023 13:29:52 GMT, Markus KARG <duke at openjdk.org> 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 one additional commit since the last revision:
> 
>   updated copyright

In the test classes `TransferTo` and `TransferTo2`, the methods `testNullPointerException` and `testStreamContents` are identical aside from expecting different `DataProvider`s. The contents of the methods could be abstracted out to common methods called by different `Test`s which expect different `DataProvider`s.

The test classes `TransferTo_2GB_transferFrom` and `TransferTo_2GB_transferTo` comprise roughly 120 lines of code each, but a diff of their contents reveals little in the way of substantive differences aside from jtreg tags, comments, and names:

96,99c95,97
<                 // performing actual transfer, effectively by multiple invocations of
<                 // FileChannel.transferFrom(ReadableByteChannel)
<                 try (InputStream inputStream = Channels.newInputStream(Channels.newChannel(
<                         new BufferedInputStream(Files.newInputStream(sourceFile))));
---
>                 // perform actual transfer, effectively by multiple invocations
>                 // of FileChannel.transferTo(WritableByteChannel)
>                 try (InputStream inputStream = Channels.newInputStream(FileChannel.open(sourceFile));

Perhaps something along these lines might work:
* rename `TransferToBase` to for example to `TransferBase` or `TransferFromToBase`;
* rename `TransferTo2` to `TransferFrom`;
* rename `TransferTo_2GB_transferX` classes to `TransferX_2GB`;
* refactor common code to `TransferBase` along the lines described above;
* refactor child classes as needed to use the common code.

Assuming the foregoing makes sense, there would remain a total of four tests. It might be possible also to merge `TransferFrom` and `TransferTo` into a single test, but I think the two tests `*_2GB*` should remain separate as they likely each have a sufficiently long run time.

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

PR: https://git.openjdk.org/jdk/pull/6711


More information about the nio-dev mailing list