public class BufferedOutputStream
- Object
- OutputStream
- BufferedOutputStream
ImplementsAutoCloseable
Known subtypesTarOutputStream
Fields
protected byte[] buf | The internal buffer where data is stored. |
protected int count | The number of valid bytes in the buffer. |
Constructors
public BufferedOutputStream(OutputStream out) | Creates a new buffered output stream to write data to the specified underlying output stream. |
public BufferedOutputStream(OutputStream out, String name) | Creates a new buffered output stream to write data to the specified underlying output stream. |
public 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. |
public 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. |
Methods
Inherited methods
Field details
buf
protected byte[] bufcount
protected int countConstructor details
BufferedOutputStream
public BufferedOutputStream(OutputStream out)Parameters
outOutputStream- the underlying output stream.
BufferedOutputStream
public BufferedOutputStream(OutputStream out, String name)Parameters
outOutputStream- the underlying output stream.
nameString- the name of the stream used for debugging/logging purposes
BufferedOutputStream
public BufferedOutputStream(OutputStream out, int size)Parameters
outOutputStream- the underlying output stream.
sizeint- the buffer size.
Throws
IllegalArgumentException- if size <= 0.
BufferedOutputStream
public BufferedOutputStream(OutputStream out, int size, String name)Parameters
outOutputStream- the underlying output stream.
sizeint- the buffer size.
nameString- the name of the stream used for debugging/logging purposes
Throws
IllegalArgumentException- if size <= 0.
Method details
getDefaultBufferSize
public static int getDefaultBufferSize()Returns
setDefaultBufferSize
public static void setDefaultBufferSize(int aDefaultBufferSize)Parameters
aDefaultBufferSizeint- the defaultBufferSize to set
getName
public String getName()Returns
flushBuffer
public synchronized void flushBuffer()
throws IOExceptionThrows
write
public synchronized void write(int b)
throws IOExceptionParameters
bint- the byte to be written.
Throws
IOException- if an I/O error occurs.
write
public synchronized void write(byte[] b, int off, int len)
throws IOExceptionWrites 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.
Parameters
bbyte[]- the data.
offint- the start offset in the data.
lenint- the number of bytes to write.
Throws
IOException- if an I/O error occurs.
flush
public synchronized void flush()
throws IOExceptionThrows
IOException- if an I/O error occurs.
getLastActivityTime
public synchronized long getLastActivityTime()Returns
getTotalBytesWritten
public synchronized int getTotalBytesWritten()Returns
setProgressListener
public void setProgressListener(IOProgressListener progressListener)Parameters
progressListenerIOProgressListener- the progressListener to set
write
public void write(byte[] b)
throws IOExceptionWrites 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.
Parameters
bbyte[]- the data to be written.
Throws
IOException- if an I/O error occurs.
close
public void close()
throws IOExceptionCloses this output stream and releases any system resources associated with the stream.
The close method of FilterOutputStream
calls its flush method, and then calls the
close method of its underlying output stream.
Throws
IOException- if an I/O error occurs.
getConnection
public Object getConnection()Returns
setConnection
public void setConnection(Object connection)Parameters
connectionObject- the connection to set