Bug in Channels.newChannel() ?

Rémi Forax forax at univ-mlv.fr
Sat Mar 26 13:43:12 PDT 2011


This snippet prints 2 and 0

     ByteArrayInputStream input = new ByteArrayInputStream(new byte[] 
{1, 2});
     ReadableByteChannel channel = Channels.newChannel(input);

     ByteBuffer buffer = ByteBuffer.allocate(2);
     System.out.println(channel.read(buffer));
     System.out.println(channel.read(buffer));

but should prints 2 and -1 because we reach the end of the stream.

Rémi




More information about the nio-dev mailing list