Updating existing JDK code to use InputStream.transferTo()

Remi Forax forax at univ-mlv.fr
Wed May 13 22:05:23 UTC 2015



On 05/13/2015 11:58 PM, Pavel Rappo wrote:
> Remi,
>
>> The other reason to have read that returns 0 is if the underlying channel is in non-blocking mode.
>> A read on an InputStream created by Channels.newInputStream on a SelectableChannel may return 0
>> and the code will go in a loop until the SelectableChannel can read something.
>> while(read() > 0) avoid that issue.
> It doesn't seem possible as far as I can see. We have 2 methods in
> java.nio.channels.Channels:
>
>     newInputStream(java.nio.channels.ReadableByteChannel)
>     newInputStream(java.nio.channels.AsynchronousByteChannel)
>
> Neither ReadableByteChannel nor AsynchronousByteChannel is SelectableChannel.

SocketChannel is a subtype of both ReadableByteChannel and 
SelectableChannel.

>
> Sorry, I might be missing something. Anyway, it would be a misbehaving
> InputStream as it doesn't conform to the spec.

if the read is non-blocking, it can read 0 byte which is conform to the 
InputStream.read spec,
or am i missing something ?

Rémi





More information about the core-libs-dev mailing list