java.lang.Object | |||
↳ | java.io.OutputStream | ||
↳ | java.io.FilterOutputStream | ||
↳ | java.io.BufferedOutputStream |
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.
BufferedOutputStream buf = new BufferedOutputStream(new FileOutputStream("file.java"));
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
buf | The buffer containing the bytes to be written to the target stream. | ||||||||||
count | The total number of bytes inside the byte array buf . |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
BufferedOutputStream , providing out with a buffer
of 8192 bytes. | |||||||||||
Constructs a new
BufferedOutputStream , providing out with size bytes
of buffer. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this stream.
| |||||||||||
Flushes this stream to ensure all pending data is written out to the
target stream.
| |||||||||||
Writes
count bytes from the byte array buffer starting at
offset to this stream. | |||||||||||
Writes one byte to this stream.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
The buffer containing the bytes to be written to the target stream.
Constructs a new BufferedOutputStream
, providing out
with a buffer
of 8192 bytes.
out | the OutputStream the buffer writes to.
|
---|
Constructs a new BufferedOutputStream
, providing out
with size
bytes
of buffer.
out | the OutputStream the buffer writes to. |
---|---|
size | the size of buffer in bytes. |
Public Methods
public
synchronized
void
flush
()
Since: API Level 1
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
(byte[] buffer, int offset, int length)
Since: API Level 1
Writes
count
bytes from the byte array buffer
starting at
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
buffer
are written to the target stream, the target is flushed,
and the buffer is cleared.
Parameters
buffer
| the buffer to be written. |
---|---|
offset
| the start position in |
length
| the number of bytes from |
Throws
IndexOutOfBoundsException
| if |
---|---|
IOException
| if an error occurs attempting to write to this stream. |
NullPointerException
| if |
ArrayIndexOutOfBoundsException
| If offset or count is outside of bounds.
|
public
synchronized
void
write
(int oneByte)
Since: API Level 1
Writes one byte to this stream. Only the low order byte of the integer
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 oneByte
are written to the target stream, the target is
flushed, and the buffer is reset.
Parameters
oneByte
| the byte to be written. |
---|