Date: Wed, 18 Jul 2001 20:47:25 -0400 (EDT)
From: ###@###.###>
To: ###@###.###, ###@###.###
Subject: Channels.newChannel bugs
FYI, there seem to be a couple of bugs in the Channels.newChannel
method implementations:
In newChannel(InputStream),
int bytesToRead = Math.min(len, TRANSFER_SIZE);
should be
int bytesToRead = Math.min((len - totalRead),
TRANSFER_SIZE);
and in newChannel(OutputStream),
int bytesToRead = Math.min(len, TRANSFER_SIZE);
should be
int bytesToRead = Math.min((len - totalWritten),
TRANSFER_SIZE);
In both cases as is, the number of bytes already transferred in
previous iterations of the while loop is not considered, so it is
possible for the buffer put/get operations to cause a
BufferOverflowException or BufferUnderflowException (respectively). I
experienced the former in practive, and the above change fixed the
problem.
From: ###@###.###>
To: ###@###.###, ###@###.###
Subject: Channels.newChannel bugs
FYI, there seem to be a couple of bugs in the Channels.newChannel
method implementations:
In newChannel(InputStream),
int bytesToRead = Math.min(len, TRANSFER_SIZE);
should be
int bytesToRead = Math.min((len - totalRead),
TRANSFER_SIZE);
and in newChannel(OutputStream),
int bytesToRead = Math.min(len, TRANSFER_SIZE);
should be
int bytesToRead = Math.min((len - totalWritten),
TRANSFER_SIZE);
In both cases as is, the number of bytes already transferred in
previous iterations of the while loop is not considered, so it is
possible for the buffer put/get operations to cause a
BufferOverflowException or BufferUnderflowException (respectively). I
experienced the former in practive, and the above change fixed the
problem.