public class MeasuredOutputStream extends OutputStream
OutputStream passes information along to an underlying
OutputStream while counting how many bytes are written.
At any point calling getWrittenCount() tells how the amount of data that has been written since this object was constructed.
Also you can add a ChangeListener to this stream to be notified every time a specific amount of bytes are written.
| Modifier and Type | Field and Description |
|---|---|
protected long |
written
|
| Constructor and Description |
|---|
MeasuredOutputStream(OutputStream
|
| Modifier and Type | Method and Description |
|---|---|
void |
addChangeListener(ChangeListener
|
void |
close()
|
protected void |
fireListeners(boolean skipThreshold)
|
void |
flush()
|
long |
getBytesWritten()
Returns the number of bytes written since this object was constructed.
|
boolean |
isClosed()
|
void |
removeChangeListener(ChangeListener
|
void |
write(byte[] b)
|
void |
write(byte[] b, int off, int len)
|
void |
write(int b)
|
public MeasuredOutputStream(OutputStreamout)
public void addChangeListener(ChangeListenerl, long interval, boolean consumeExceptions)
l - the listener to add
interval - the amount of bytes to write before notifying the listener. Must be 1 or greater. The listener will be notified each time this threshold is crossed, or when this stream is closed.
consumeExceptions - is true, then exceptions that occur while calling ChangeListener.stateChanged(..) are printed to the console. If false: they are allowed to ripple outward and interrupt calls to OutputStream.write(..) or OutputStream.close().
public void removeChangeListener(ChangeListenerl)
protected void fireListeners(boolean skipThreshold)
public long getBytesWritten()
public void close()
throws IOException
close in interface
Closeable
close in interface
AutoCloseable
close in class
OutputStream
IOException
public boolean isClosed()
public void flush()
throws IOException
flush in interface
Flushable
flush in class
OutputStream
IOException
public void write(byte[] b,
int off,
int len)
throws IOException
write in class
OutputStream
IOException
public void write(byte[] b)
throws IOException
write in class
OutputStream
IOException
public void write(int b)
throws IOException
write in class
OutputStream
IOException