public final class CountingOutputStream extends OutputStream implements ConnectedTestable
Instances of this class are not safe for use by multiple threads.
| Constructor and Description |
|---|
CountingOutputStream()
Create an empty counting output stream decorator.
|
CountingOutputStream(OutputStream stream)
Create a counting output stream decorator around a given output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearDisconnectedBuffer()
Remove all buffered and therefore not yet written bytes from the internal disconnected buffer.
|
void |
close() |
void |
flush() |
long |
getCount()
Get the count of all exported bytes.
|
boolean |
isConnected()
Answer whether this object is currently connected.
|
void |
removeStream()
Remove the output stream to be decorated.
|
void |
removeStream(boolean resetCounter,
boolean clearBuffer)
Remove the output stream to be decorated.
|
void |
setCount(long count)
Set the count of all exported bytes to a given value.
|
void |
setStream(OutputStream stream)
Set the output stream to be decorated or null if you want to remove the current stream.
|
void |
setStream(OutputStream stream,
boolean resetCounter,
boolean clearBuffer)
Set the output stream to be decorated or null if you want to remove the current stream.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
public CountingOutputStream()
public CountingOutputStream(OutputStream stream)
stream - The output stream to be decoratedpublic final void setStream(OutputStream stream)
An already existing stream will be removed before.
The counter will not be reset and the internal disconnected buffer will not be cleared.
stream - The output stream to be decoratedpublic final void setStream(OutputStream stream, boolean resetCounter, boolean clearBuffer)
An already existing stream will be removed before.
stream - The output stream to be decoratedresetCounter - Flag whether the counter has to be reset to zeroclearBuffer - Flag whether to remove all buffered and therefore not yet written bytes from the internal
disconnected bufferpublic final void removeStream()
The counter will not be reset and the internal disconnected buffer will not be cleared.
public final void removeStream(boolean resetCounter,
boolean clearBuffer)
resetCounter - Flag whether the counter has to be reset to zeroclearBuffer - Flag whether to remove all buffered and therefore not yet written bytes from the internal
disconnected bufferpublic final long getCount()
public final void setCount(long count)
count - The count to be setpublic final void clearDisconnectedBuffer()
public final void write(int b)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic final void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic final boolean isConnected()
ConnectedTestableisConnected in interface ConnectedTestablepublic final void close()
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamCopyright © 2019. All rights reserved.