java.lang.Object
java.io.OutputStream
org.omnifaces.io.ResettableBufferedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,ResettableBuffer
This resettable buffered output stream will buffer everything until the given threshold buffer size, regardless of
flush calls. Only when the specified threshold buffer size is exceeded, or when
close() is called, then the
buffer will be actually flushed.
There is a reset() method which enables the developer to reset the buffer, as long as it's not flushed yet,
which can be determined by isResettable().
- Author:
- Bauke Scholtz
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionResettableBufferedOutputStream(int thresholdBufferSize) Construct a new resettable buffered output stream which forcibly buffers everything until the given threshold buffer size, regardless of flush calls and calls.ResettableBufferedOutputStream(OutputStream output, int thresholdBufferSize) Construct a new resettable buffered output stream which wraps the given output stream and forcibly buffers everything until the given threshold buffer size, regardless of flush calls. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected OutputStreamcreateOutputStream(boolean thresholdBufferSizeExceeded) Returns the custom implementation of theOutputStream.voidflush()protected intReturns the amount of so far written bytes in the threshold buffer.booleanReturns true if buffer can be reset.voidreset()Perform a buffer reset.voidwrite(byte[] bytes) voidwrite(byte[] bytes, int offset, int length) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ResettableBufferedOutputStream
public ResettableBufferedOutputStream(int thresholdBufferSize) Construct a new resettable buffered output stream which forcibly buffers everything until the given threshold buffer size, regardless of flush calls and calls. You need to overridecreateOutputStream(boolean)when using this constructor.- Parameters:
thresholdBufferSize- The threshold buffer size.
-
ResettableBufferedOutputStream
Construct a new resettable buffered output stream which wraps the given output stream and forcibly buffers everything until the given threshold buffer size, regardless of flush calls. You do not need to overridecreateOutputStream(boolean)when using this constructor.- Parameters:
output- The wrapped output stream .thresholdBufferSize- The threshold buffer size.
-
-
Method Details
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
createOutputStream
Returns the custom implementation of theOutputStream. This will only be called when the specified threshold buffer size is exceeded, or whenclose()is called.- Parameters:
thresholdBufferSizeExceeded- Whether the threshold buffer size has exceeded.- Returns:
- The custom implementation of the
OutputStream. - Throws:
IOException- When an I/O error occurs.
-
getWrittenBytes
protected int getWrittenBytes()Returns the amount of so far written bytes in the threshold buffer. This will be 0 when the threshold buffer is empty and this will be -1 when the threshold has exceeded.- Returns:
- The amount of so far written bytes in the threshold buffer.
-
reset
public void reset()Description copied from interface:ResettableBufferPerform a buffer reset.- Specified by:
resetin interfaceResettableBuffer
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
isResettable
public boolean isResettable()Description copied from interface:ResettableBufferReturns true if buffer can be reset.- Specified by:
isResettablein interfaceResettableBuffer- Returns:
trueif buffer can be reset, otherwisefalse.
-