Class BufferedOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
- Direct Known Subclasses:
TarOutputStream
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this output stream and releases any system resources associated with the stream.voidflush()Flushes this buffered output stream.voidFlush the internal bufferIf applicable this member represents the connection object for the streamstatic intThe default size for a stream bufferlongReturns the time of the last activitygetName()Indicates the name of the stream for debugging purposesintReturns the total amount of bytes written to this stream so farvoidsetConnection(Object connection) If applicable this member represents the connection object for the streamstatic voidsetDefaultBufferSize(int aDefaultBufferSize) The default size for a stream buffervoidsetProgressListener(IOProgressListener progressListener) Sets the callback for IO updates from a buffered streamvoidwrite(byte[] b) Writesb.lengthbytes to this output stream.voidwrite(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto this buffered output stream.voidwrite(int b) Writes the specified byte to this buffered output stream.
-
Field Details
-
buf
protected byte[] bufThe internal buffer where data is stored. -
count
protected int countThe 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
Creates a new buffered output stream to write data to the specified underlying output stream.
Parameters
out: the underlying output stream.
-
BufferedOutputStream
Creates a new buffered output stream to write data to the specified underlying output stream.
Parameters
-
out: the underlying output stream. -
name: the name of the stream used for debugging/logging purposes
-
-
BufferedOutputStream
Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.
Parameters
-
out: the underlying output stream. -
size: the buffer size.
Throws
IllegalArgumentException: if size <= 0.
-
-
BufferedOutputStream
Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.
Parameters
-
out: the underlying output stream. -
size: the buffer size. -
name: 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: the defaultBufferSize to set
-
getName
Indicates the name of the stream for debugging purposes
Returns
the name of the stream
-
flushBuffer
-
write
Writes the specified byte to this buffered output stream.
Parameters
b: the byte to be written.
Throws
IOException: if an I/O error occurs.
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
Writes
lenbytes from the specified byte array starting at offsetoffto 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: the data. -
off: the start offset in the data. -
len: the number of bytes to write.
Throws
IOException: if an I/O error occurs.
- Overrides:
writein classOutputStream- Throws:
IOException
-
-
flush
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.
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
getLastActivityTime
public long getLastActivityTime()Returns the time of the last activity
Returns
time of the last activity on this stream
-
getTotalBytesWritten
public 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
Sets the callback for IO updates from a buffered stream
Parameters
progressListener: the progressListener to set
-
write
Writes
b.lengthbytes to this output stream.The
writemethod ofFilterOutputStreamcalls itswritemethod of three arguments with the argumentsb,0, andb.length.Note that this method does not call the one-argument
writemethod of its underlying stream with the single argumentb.Parameters
b: the data to be written.
Throws
IOException: if an I/O error occurs.
- Overrides:
writein classOutputStream- Throws:
IOException
-
close
Closes this output stream and releases any system resources associated with the stream.
The
closemethod ofFilterOutputStreamcalls itsflushmethod, and then calls theclosemethod of its underlying output stream.Throws
IOException: if an I/O error occurs.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
getConnection
If applicable this member represents the connection object for the stream
Returns
the connection
-
setConnection
If applicable this member represents the connection object for the stream
Parameters
connection: the connection to set
-