Bug in Channels.newChannel() ?

Rémi Forax forax at univ-mlv.fr
Sun Mar 27 11:39:03 PDT 2011


On 03/27/2011 07:16 PM, Alan Bateman wrote:
> Rémi Forax wrote:
>> :
>>
>>     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.
> As it happens I submitted a bug against java.io.ByteArrayInputStream 
> some time ago on this:
>  http://bugs.sun.com/view_bug.do?bug_id=6766844
>
> I'd forgotten about that one.
>
> -Alan.

Ok, I've re-read the javadoc of InputStream.read(),
you're right.

I think the doc of ReadableByteChannel can be improved
to say that read returns 0 if buffer.hasRemaining() returns 0.

I propose:
"An attempt is made to read up to /r/ bytes from the channel,
where /r/ is the number of bytes remaining in the buffer, that is, 
dst.remaining(),
at the moment this method is invoked.
If dst.hasRemaining() is false, then no bytes are read and read returns |0.
|
Rémi|

|

||

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20110327/1357a14c/attachment.html 


More information about the nio-dev mailing list