java.io.BufferedOutputStream
java.io.FilterOutputStream
None
None
JDK 1.0 or later
A BufferedOutputStream object provides a more efficient way to write just a few bytes at a time to an OutputStream. BufferedOutputStream objects use a buffer to store output for an associated OutputStream. In other words, a large number of bytes are stored in an internal buffer and only written when the buffer fills up or is explicitly flushed. A BufferedOutputStream is more efficient than a regular OutputStream because the data is written to memory, rather than a disk or a network. Minimizing the number of write operations to a disk or the network minimizes the cumulative overhead for these operations.
You should wrap a BufferedOutputStream around any OutputStream whose write() operations may be time consuming or costly, such as a FileOutputStream.
public class java.io.BufferedOutputStream extends java.io.FilterOutputStream { // Variables protected byte[] buf; protected int count; // Constructors public BufferedOutputStream(OutputStream out); public BufferedOutputStream(OutputStream out, int size); // Instance Methods public synchronized void flush(); public synchronized void write(int b); public synchronized void write(byte[] b, int off, int len); }
The buffer that stores the data for the output stream.
The current position in the buffer.
The output stream to buffer.
This constructor creates a BufferedOutputStream that acts on the specified OutputStream, using a buffer with the default size of 512 bytes.
The output stream to buffer.
The size of buffer to use.
This constructor creates a BufferedOutputStream that acts on the specified OutputStream, using a buffer that is size bytes long.
If any kind of I/O error occurs.
FilterOutputStream.flush()
This method writes the contents of the buffer to the underlying output stream. It is called automatically when the buffer fills up. You can also call it before the buffer is full. This is known as "flushing" the buffer. This method blocks until the underlying write() is complete.
The value to write.
If any kind of I/O error occurs.
FilterOutputStream.write(int)
This method places a byte containing the low-order eight bits of the given integer into the buffer. If the buffer is full, it is flushed, and the value b is placed in the newly empty buffer. If the buffer is flushed, this method blocks until flush() returns; otherwise this method returns immediately.
public synchronized void write(byte b[], int off, int len) throws IOException
An array of bytes to write to the stream.
An offset into the byte array.
The number of bytes to write.
If any kind of I/O error occurs.
FilterOutputStream.write(byte[], int, int)
This method copies len bytes from b, starting at off, into the buffer. If there is enough space left in the buffer for the new data, it is copied into the buffer and the method returns immediately. Otherwise, the buffer is flushed, and the new data is written directly to the underlying stream. This is subtly different from the behavior of write(int), which places new data in the buffer after a flush().
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
close() |
FilterOutputStream |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
write(byte[]) |
FilterOutputStream |
FilterOutputStream, IOException, OutputStream