- java.lang.Object
-
- java.io.OutputStream
-
- org.omnifaces.io.ResettableBufferedOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,ResettableBuffer
public class ResettableBufferedOutputStream extends OutputStream implements 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 whenclose()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 byisResettable().- Author:
- Bauke Scholtz
- See Also:
ResettableBufferedWriter
-
-
Constructor Summary
Constructors Constructor Description 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.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected OutputStreamcreateOutputStream(boolean thresholdBufferSizeExceeded)Returns the custom implementation of theOutputStream.voidflush()protected intgetWrittenBytes()Returns the amount of so far written bytes in the threshold buffer.booleanisResettable()Returns 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 Detail
-
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
public 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. You do not need to overridecreateOutputStream(boolean)when using this constructor.- Parameters:
output- The wrapped output stream .thresholdBufferSize- The threshold buffer size.
-
-
Method Detail
-
write
public void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] bytes) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] bytes, int offset, int length) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
createOutputStream
protected OutputStream createOutputStream(boolean thresholdBufferSizeExceeded) throws IOException
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
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- 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.
-
-