Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » io » [javadoc | source]
java.io
public class: BufferedOutputStream [javadoc | source]
java.lang.Object
   java.io.OutputStream
      java.io.FilterOutputStream
         java.io.BufferedOutputStream

All Implemented Interfaces:
    Flushable, Closeable

Wraps an existing OutputStream and buffers the output. Expensive interaction with the underlying input stream is minimized, since most (smaller) requests can be satisfied by accessing the buffer alone. The drawback is that some extra space is required to hold the buffer and that copying takes place when flushing that buffer, but this is usually outweighed by the performance benefits.

A typical application pattern for the class looks like this:

BufferedOutputStream buf = new BufferedOutputStream(new FileOutputStream("file.java"));
Field Summary
protected  byte[] buf    The buffer containing the bytes to be written to the target stream. 
protected  int count    The total number of bytes inside the byte array {@code buf}. 
Fields inherited from java.io.FilterOutputStream:
out
Constructor:
 public BufferedOutputStream(OutputStream out) 
    Constructs a new {@code BufferedOutputStream} on the OutputStream {@code out}. The buffer size is set to the default value of 8 KB.
    Parameters:
    out - the {@code OutputStream} for which write operations are buffered.
 public BufferedOutputStream(OutputStream out,
    int size) 
    Constructs a new {@code BufferedOutputStream} on the OutputStream {@code out}. The buffer size is set to {@code size}.
    Parameters:
    out - the output stream for which write operations are buffered.
    size - the size of the buffer in bytes.
    Throws:
    IllegalArgumentException - if {@code size <= 0}.
Method from java.io.BufferedOutputStream Summary:
close,   flush,   write,   write
Methods from java.io.FilterOutputStream:
close,   flush,   write,   write,   write
Methods from java.io.OutputStream:
checkError,   close,   flush,   write,   write,   write
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.BufferedOutputStream Detail:
 public synchronized  void close() throws IOException 
 public synchronized  void flush() throws IOException 
    Flushes this stream to ensure all pending data is written out to the target stream. In addition, the target stream is flushed.
 public synchronized  void write(int oneByte) throws IOException 
    Writes one byte to this stream. Only the low order byte of the integer {@code oneByte} is written. If there is room in the buffer, the byte is copied into the buffer and the count incremented. Otherwise, the buffer plus {@code oneByte} are written to the target stream, the target is flushed, and the buffer is reset.
 public synchronized  void write(byte[] buffer,
    int offset,
    int length) throws IOException 
    Writes {@code count} bytes from the byte array {@code buffer} starting at {@code offset} to this stream. If there is room in the buffer to hold the bytes, they are copied in. If not, the buffered bytes plus the bytes in {@code buffer} are written to the target stream, the target is flushed, and the buffer is cleared.