RFR: 8265891: ChannelInputStream.transferTo() uses FileChannel.transferTo()

Alan Bateman alanb at openjdk.java.net
Thu Aug 19 18:28:29 UTC 2021


On Thu, 19 Aug 2021 17:47:00 GMT, Markus KARG <github.com+1701815+mkarg at openjdk.org> wrote:

> This is not true. It will only check the blocking mode for the target. But technically it is possible that someone writes an implementation of FileChannel which implements SelectableChannel. In that case it is needed to check the blocking mode on the source, too. So either we (a) ignore this possibility, (b) write a very complex code which calls transfer(fc, target) in FOUR code paths not just two, or (c) we keep the ThrowingLongSupplier as an elegant way to perform the 2x2 matrix.

SelectableChannel is an abstract class, not an interface so you can't extend both FileChannel and SelectableChannel. So when the source channel is a FileChannel then it should only be concerned with whether the target channel is a SelectableChannel or not. I think we can keep it very simple, along the lines of the method I pasted in above.

If you choose to include the case where the target is a SelectableChannel (and I have no objection to doing that) then the test needs to exercise that code. This means the test needs an input stream created on a source file/FileChannel, and an output stream created an channel that is WritableByteChannel & SelectableChannel. A Pipe.SinkChannel or a connected SocketChannel will do fine. If you choose to leave out selectable channels for the first PR then file -> file is okay, which I think is what your current test is doing.

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

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


More information about the nio-dev mailing list