Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4051547
Votes 0
Synopsis java.io.BufferedOutputStream does not flush immediately when buffer is full
Category java:classes_io
Reported Against 1.1.1
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 5-Very Low
Related Bugs
Submit Date 13-MAY-1997
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;
    }
Work Around
N/A
Evaluation
The specification in the JLS does not require the BufferedOutputStream class to
flush its buffer at the moment that it becomes full.  --  xxxxx@xxxxx  1/7/1998
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang