Class ResettableBufferedOutputStream
java.lang.Object
java.io.OutputStream
org.openremote.container.web.file.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()
.
- 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 TypeMethodDescriptionvoid
close()
protected OutputStream
createOutputStream
(boolean thresholdBufferSizeExceeded) Returns the custom implementation of theOutputStream
.void
flush()
protected int
Returns the amount of so far written bytes in the threshold buffer.boolean
Returns true if buffer can be reset.void
reset()
Perform a buffer reset.void
write
(byte[] bytes) void
write
(byte[] bytes, int offset, int length) void
write
(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:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in 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:ResettableBuffer
Perform a buffer reset.- Specified by:
reset
in interfaceResettableBuffer
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
isResettable
public boolean isResettable()Description copied from interface:ResettableBuffer
Returns true if buffer can be reset.- Specified by:
isResettable
in interfaceResettableBuffer
- Returns:
true
if buffer can be reset, otherwisefalse
.
-