|
Description
|
I have been examining a problem in java.io.BufferedOutputStream I noticed
that the following code will not flush the buffer when it is just full and
so wait for the next write operation to that stream
If the BufferedOutputStream is 512 bytes, and you have 510 bytes in the buffer
and then add only 2 bytes
Then it misses the first case 2 is not > 512
it misses the second case 2 > 512-510
it fills the buffer, but then will not flush until the next write op
public synchronized void write(byte b[], int off, int len) throws IOException {
if (len >= buf.length) {
/* If the request length exceeds the size of the output buffer,
flush the output buffer and then write the data directly.
In this way buffered streams will cascade harmlessly. */
flushBuffer();
out.write(b, off, len);
return;
}
if (len > buf.length - count) {
flushBuffer();
}
System.arraycopy(b, off, buf, count, len);
count += len;
}
|