public class BufferedOutputStream extends OutputStream
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The internal buffer where data is stored.
|
protected int |
count
The number of valid bytes in the buffer.
|
| Constructor and Description |
|---|
BufferedOutputStream(OutputStream out)
Creates a new buffered output stream to write data to the
specified underlying output stream.
|
BufferedOutputStream(OutputStream out,
int size)
Creates a new buffered output stream to write data to the
specified underlying output stream with the specified buffer
size.
|
BufferedOutputStream(OutputStream out,
int size,
String name)
Creates a new buffered output stream to write data to the
specified underlying output stream with the specified buffer
size.
|
BufferedOutputStream(OutputStream out,
String name)
Creates a new buffered output stream to write data to the
specified underlying output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this output stream and releases any system resources
associated with the stream.
|
void |
flush()
Flushes this buffered output stream.
|
void |
flushBuffer()
Flush the internal buffer
|
Object |
getConnection()
If applicable this member represents the connection object for the stream
|
static int |
getDefaultBufferSize()
The default size for a stream buffer
|
long |
getLastActivityTime()
Returns the time of the last activity
|
String |
getName()
Indicates the name of the stream for debugging purposes
|
int |
getTotalBytesWritten()
Returns the total amount of bytes written to this stream so far
|
void |
setConnection(Object connection)
If applicable this member represents the connection object for the stream
|
static void |
setDefaultBufferSize(int aDefaultBufferSize)
The default size for a stream buffer
|
void |
setProgressListener(IOProgressListener progressListener)
Sets the callback for IO updates from a buffered stream
|
void |
write(byte[] b)
Writes
b.length bytes to this output stream. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to this buffered output stream. |
void |
write(int b)
Writes the specified byte to this buffered output stream.
|
protected byte[] buf
protected int count
public BufferedOutputStream(OutputStream out)
out - the underlying output stream.public BufferedOutputStream(OutputStream out, String name)
out - the underlying output stream.name - the name of the stream used for debugging/logging purposespublic BufferedOutputStream(OutputStream out, int size)
out - the underlying output stream.size - the buffer size.IllegalArgumentException - if size <= 0.public BufferedOutputStream(OutputStream out, int size, String name)
out - the underlying output stream.size - the buffer size.name - the name of the stream used for debugging/logging purposesIllegalArgumentException - if size <= 0.public String getName()
public void flushBuffer()
throws IOException
IOExceptionpublic void write(int b)
throws IOException
write in class OutputStreamb - the byte to be written.IOException - if an I/O error occurs.public void write(byte[] b,
int off,
int len)
throws IOException
len bytes from the specified byte array
starting at offset off to this buffered output stream.
Ordinarily this method stores bytes from the given array into this
stream's buffer, flushing the buffer to the underlying output stream as
needed. If the requested length is at least as large as this stream's
buffer, however, then this method will flush the buffer and write the
bytes directly to the underlying output stream. Thus redundant
BufferedOutputStreams will not copy data unnecessarily.
write in class OutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.IOException - if an I/O error occurs.public void flush()
throws IOException
flush in class OutputStreamIOException - if an I/O error occurs.public long getLastActivityTime()
public int getTotalBytesWritten()
public void setProgressListener(IOProgressListener progressListener)
progressListener - the progressListener to setpublic static int getDefaultBufferSize()
public static void setDefaultBufferSize(int aDefaultBufferSize)
aDefaultBufferSize - the defaultBufferSize to setpublic void write(byte[] b)
throws IOException
b.length bytes to this output stream.
The write method of FilterOutputStream
calls its write method of three arguments with the
arguments b, 0, and
b.length.
Note that this method does not call the one-argument
write method of its underlying stream with the single
argument b.
write in class OutputStreamb - the data to be written.IOException - if an I/O error occurs.public void close()
throws IOException
The close method of FilterOutputStream
calls its flush method, and then calls the
close method of its underlying output stream.
close in interface AutoCloseableclose in class OutputStreamIOException - if an I/O error occurs.public Object getConnection()
public void setConnection(Object connection)
connection - the connection to set