java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
net.i2p.i2ptunnel.util.LimitOutputStream
net.i2p.i2ptunnel.util.ByteLimitOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
An OutputStream that limits how many bytes are written, throwing
EOFException when the limit is exceeded.Nested Class Summary
Nested classes/interfaces inherited from class LimitOutputStream
LimitOutputStream.DoneCallbackModifier and TypeClassDescriptionstatic interfaceCallback interface for notification when a limited output stream completes.Field Summary
FieldsFields inherited from class LimitOutputStream
_callback, _isDoneModifier and TypeFieldDescriptionprotected final LimitOutputStream.DoneCallbackInvoked once byLimitOutputStream.setDone()when the subclass has finished writing.protected booleanTrue once setDone() has run, so the callback cannot fire twice.Fields inherited from class FilterOutputStream
outConstructor Summary
ConstructorsConstructorDescriptionByteLimitOutputStream(OutputStream out, LimitOutputStream.DoneCallback done, long limit) Creates a new byte-limited output stream.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidwrite(byte[] src, int off, int len) Subclasses MUST override the following method such that it calls done() when finished and throws EOFException if called again.Methods inherited from class LimitOutputStream
isDone, setDone, writeMethods inherited from class FilterOutputStream
close, flush, writeMethods inherited from class OutputStream
nullOutputStream
Field Details
_limit
private final long _limitMost bytes the stream will accept._count
private long _countBytes written so far.
Constructor Details
ByteLimitOutputStream
Creates a new byte-limited output stream.- Parameters:
out- the underlying output streamdone- callback invoked when the limit is reachedlimit- maximum number of bytes allowed, must be greater than zero- Throws:
IllegalArgumentException- if limit is not greater than zero
Method Details
write
Description copied from class:LimitOutputStreamSubclasses MUST override the following method such that it calls done() when finished and throws EOFException if called again.- Overrides:
writein classLimitOutputStream- Throws:
IOException