public class BufferedOutputStream

  1. Object
  2. OutputStream
  3. BufferedOutputStream

ImplementsAutoCloseable

Known subtypesTarOutputStream

Based on the buffered output stream from the JDK with some minor tweaks to allow external classes to monitor stream status and progress.

Fields

protected byte[] bufThe internal buffer where data is stored.
protected int countThe 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

public static int getDefaultBufferSize()The default size for a stream buffer
public static void setDefaultBufferSize(int aDefaultBufferSize)The default size for a stream buffer
public String getName()Indicates the name of the stream for debugging purposes
public synchronized void flushBuffer() throws IOExceptionFlush the internal buffer
public synchronized void write(int b) throws IOExceptionWrites the specified byte to this buffered output stream.
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.
public synchronized void flush() throws IOExceptionFlushes this buffered output stream.
public synchronized long getLastActivityTime()Returns the time of the last activity
public synchronized int getTotalBytesWritten()Returns the total amount of bytes written to this stream so far
public void setProgressListener(IOProgressListener progressListener)Sets the callback for IO updates from a buffered stream
public void write(byte[] b) throws IOExceptionWrites b.length bytes to this output stream.
public void close() throws IOExceptionCloses this output stream and releases any system resources associated with the stream.
public Object getConnection()If applicable this member represents the connection object for the stream
public void setConnection(Object connection)If applicable this member represents the connection object for the stream

Inherited methods

Field details

buf

protected byte[] buf
The internal buffer where data is stored.

count

protected int count
The number of valid bytes in the buffer. This value is always in the range 0 through buf.length; elements buf[0] through buf[count-1] contain valid byte data.

Constructor details

BufferedOutputStream

public BufferedOutputStream(OutputStream out)
Creates a new buffered output stream to write data to the specified underlying output stream.

Parameters

out OutputStream
the underlying output stream.

BufferedOutputStream

public BufferedOutputStream(OutputStream out, String name)
Creates a new buffered output stream to write data to the specified underlying output stream.

Parameters

out OutputStream
the underlying output stream.
name String
the name of the stream used for debugging/logging purposes

BufferedOutputStream

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.

Parameters

out OutputStream
the underlying output stream.
size int
the buffer size.

Throws

IllegalArgumentException
if size <= 0.

BufferedOutputStream

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.

Parameters

out OutputStream
the underlying output stream.
size int
the buffer size.
name String
the name of the stream used for debugging/logging purposes

Throws

IllegalArgumentException
if size <= 0.

Method details

getDefaultBufferSize

public static int getDefaultBufferSize()
The default size for a stream buffer

Returns

the defaultBufferSize

setDefaultBufferSize

public static void setDefaultBufferSize(int aDefaultBufferSize)
The default size for a stream buffer

Parameters

aDefaultBufferSize int
the defaultBufferSize to set

getName

public String getName()
Indicates the name of the stream for debugging purposes

Returns

the name of the stream

flushBuffer

public synchronized void flushBuffer() throws IOException
Flush the internal buffer

write

public synchronized void write(int b) throws IOException
Writes the specified byte to this buffered output stream.

Parameters

b int
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 IOException

Writes 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

b byte[]
the data.
off int
the start offset in the data.
len int
the number of bytes to write.

Throws

IOException
if an I/O error occurs.

flush

public synchronized void flush() throws IOException
Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream.

Throws

IOException
if an I/O error occurs.

getLastActivityTime

public synchronized long getLastActivityTime()
Returns the time of the last activity

Returns

time of the last activity on this stream

getTotalBytesWritten

public synchronized int getTotalBytesWritten()
Returns the total amount of bytes written to this stream so far

Returns

the total amount of bytes written to this stream so far

setProgressListener

public void setProgressListener(IOProgressListener progressListener)
Sets the callback for IO updates from a buffered stream

Parameters

progressListener IOProgressListener
the progressListener to set

write

public void write(byte[] b) throws IOException

Writes 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

b byte[]
the data to be written.

Throws

IOException
if an I/O error occurs.

close

public void close() throws IOException

Closes 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()
If applicable this member represents the connection object for the stream

Returns

the connection

setConnection

public void setConnection(Object connection)
If applicable this member represents the connection object for the stream

Parameters

connection Object
the connection to set