org.omnifaces.io
Class ResettableBufferedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.omnifaces.io.ResettableBufferedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, ResettableBuffer

public class ResettableBufferedOutputStream
extends java.io.OutputStream
implements ResettableBuffer

This resettable buffered output stream will buffer everything until the given buffer size, regardless of flush calls. Only when the 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:
ResettableBufferedWriter

Constructor Summary
ResettableBufferedOutputStream(java.io.OutputStream output, int bufferSize)
          Construct a new resettable buffered output stream which wraps the given output stream and forcibly buffers everything until the given buffer size, regardless of flush calls.
 
Method Summary
 void close()
           
 void flush()
           
 boolean isResettable()
          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.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResettableBufferedOutputStream

public ResettableBufferedOutputStream(java.io.OutputStream output,
                                      int bufferSize)
Construct a new resettable buffered output stream which wraps the given output stream and forcibly buffers everything until the given buffer size, regardless of flush calls.

Parameters:
output - The wrapped output stream .
bufferSize - The buffer size.
Method Detail

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] bytes)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] bytes,
                  int offset,
                  int length)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

reset

public void reset()
Description copied from interface: ResettableBuffer
Perform a buffer reset.

Specified by:
reset in interface ResettableBuffer

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

isResettable

public boolean isResettable()
Description copied from interface: ResettableBuffer
Returns true if buffer can be reset.

Specified by:
isResettable in interface ResettableBuffer
Returns:
true if buffer can be reset, otherwise false.