Bug in Channels.newChannel() ?

Alan Bateman Alan.Bateman at oracle.com
Sun Mar 27 06:23:51 PDT 2011


Rémi Forax wrote:
> :
> The equivalent code using the InputStream:
>
>     ByteArrayInputStream input2 = new ByteArrayInputStream(new byte[] 
> {1, 2});
>     System.out.println(input2.read(new byte[2]));
>     System.out.println(input2.read(new byte[0]));
>
> prints 2 and -1.
>
> So even if the bytebuffer has no remaining bytes, it should call read.
This seems to an oddity with ByteArrayInputStream as calling 
InputStream.read with a zero length byte array should return 0. If you 
invoke a channel's read method with a buffer that has zero bytes 
remaining then it should return 0, it can't from the channel (or the 
underlying input stream in this case) because there is nowhere to put 
any bytes that is reads.

-Alan.


More information about the nio-dev mailing list