Package com.globalmentor.io
Class ProgressOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.globalmentor.io.OutputStreamDecorator<java.io.OutputStream>
-
- com.globalmentor.io.ProgressOutputStream
-
- All Implemented Interfaces:
Disposable
,java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class ProgressOutputStream extends OutputStreamDecorator<java.io.OutputStream>
An output stream that provides progres events for bytes written.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description ProgressOutputStream(java.io.OutputStream outputStream)
Decorates the given output stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProgressListener(ProgressListener progressListener)
Adds a progress listener.void
fireProgressed(long delta, long value, long maximum)
Fires a progress event to all registered progress listeners.protected void
fireProgressed(ProgressEvent progressEvent)
Fires a given progress event to all registered progress listeners.void
removeProgressListener(ProgressListener progressListener)
Removes an progress listener.void
write(byte[] bytes)
Writes all the bytes from the specified byte array to the decorated output stream.void
write(byte[] bytes, int offset, int length)
Writes specified number of bytes from the specified byte array to the decorated output stream starting at the given offset.void
write(int b)
Writes the specified byte to the decorated output stream.-
Methods inherited from class com.globalmentor.io.OutputStreamDecorator
afterClose, beforeClose, checkOutputStream, close, close, dispose, finalize, flush, getOutputStream, setOutputStream
-
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
Writes the specified byte to the decorated output stream. This version delegates towrite(int)
to ensure that no bytes written are noted more than once- Overrides:
write
in classOutputStreamDecorator<java.io.OutputStream>
- Parameters:
b
- The byte to write.- Throws:
java.io.IOException
- if an I/O error occurs.
-
write
public void write(byte[] bytes) throws java.io.IOException
Writes all the bytes from the specified byte array to the decorated output stream. This version delegates towrite(byte[], int, int)
to ensure that no bytes written are noted more than once- Overrides:
write
in classOutputStreamDecorator<java.io.OutputStream>
- Parameters:
bytes
- The bytes to write.- Throws:
java.lang.NullPointerException
- if the given byte array isnull
.java.io.IOException
- if an I/O error occurs.
-
write
public void write(byte[] bytes, int offset, int length) throws java.io.IOException
Writes specified number of bytes from the specified byte array to the decorated output stream starting at the given offset.- Overrides:
write
in classOutputStreamDecorator<java.io.OutputStream>
- Parameters:
bytes
- The bytes to write.offset
- The start offset in the data.length
- The number of bytes to write.- Throws:
java.lang.NullPointerException
- if the given byte array isnull
.java.lang.IndexOutOfBoundsException
- if the given offset is negative, or the given offset plus the given length is greater than the length of the given array.java.io.IOException
- if an I/O error occurs.
-
addProgressListener
public void addProgressListener(ProgressListener progressListener)
Adds a progress listener.- Parameters:
progressListener
- The progress listener to add.
-
removeProgressListener
public void removeProgressListener(ProgressListener progressListener)
Removes an progress listener.- Parameters:
progressListener
- The progress listener to remove.
-
fireProgressed
public void fireProgressed(long delta, long value, long maximum)
Fires a progress event to all registered progress listeners. This method delegates tofireProgressed(ProgressEvent)
.- Parameters:
delta
- The amount of recent progress, or-1
if not known.value
- The total progress to this point, or-1
if not known.maximum
- The goal, or-1
if not known.- See Also:
ProgressListener
,ProgressEvent
-
fireProgressed
protected void fireProgressed(ProgressEvent progressEvent)
Fires a given progress event to all registered progress listeners.- Parameters:
progressEvent
- The progress event to fire.
-
-