Package net.targetr.wtm3.io
Class MonitoredOutputStream
java.lang.Object
java.io.OutputStream
net.targetr.wtm3.io.MonitoredOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Keeps track of how many bytes are written to an output stream.
Used for statistical purposes.
- Author:
- Dr Michael Gardiner
-
Constructor Summary
ConstructorsConstructorDescriptionMonitoredOutputStream
(OutputStream out, AtomicLong counter) Decorates a stream with the ability to monitor how much data is transferred. -
Method Summary
Modifier and TypeMethodDescriptionboolean
For detecting if the response has started.void
close()
void
flush()
void
setInterception
(OutputStream interception) Adds an output stream to receive data written to this output stream.toString()
void
write
(byte[] data, int off, int len) void
write
(int b) Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Constructor Details
-
MonitoredOutputStream
Decorates a stream with the ability to monitor how much data is transferred.- Parameters:
out
- The output stream to monitor.counter
- The counter that should be incremented.
-
-
Method Details
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
toString
-
canRelayError
public boolean canRelayError()For detecting if the response has started. If a response has started we can not write an error response.- Returns:
- true if an error can be sent on the input stream.
-
setInterception
Adds an output stream to receive data written to this output stream.- Parameters:
interception
- where to send intercepted data.
-