org.omnifaces.io
Class ResettableBufferedWriter
java.lang.Object
java.io.Writer
org.omnifaces.io.ResettableBufferedWriter
- All Implemented Interfaces:
- java.io.Closeable, java.io.Flushable, java.lang.Appendable, ResettableBuffer
public class ResettableBufferedWriter
- extends java.io.Writer
- implements ResettableBuffer
This resettable buffered writer 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:
ResettableBufferedOutputStream
Fields inherited from class java.io.Writer |
lock |
Constructor Summary |
ResettableBufferedWriter(java.io.Writer writer,
int bufferSize,
java.lang.String characterEncoding)
Construct a new resettable buffered writer which wraps the given writer and forcibly buffers everything until
the given buffer size in bytes, 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(char[] chars,
int offset,
int length)
|
Methods inherited from class java.io.Writer |
append, append, append, write, write, write, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ResettableBufferedWriter
public ResettableBufferedWriter(java.io.Writer writer,
int bufferSize,
java.lang.String characterEncoding)
- Construct a new resettable buffered writer which wraps the given writer and forcibly buffers everything until
the given buffer size in bytes, regardless of flush calls. The given character encoding is used to measure the
amount of already written bytes in the buffer.
regardless of flush calls.
- Parameters:
writer
- The wrapped writer.bufferSize
- The buffer size.characterEncoding
- The character encoding.
write
public void write(char[] chars,
int offset,
int length)
throws java.io.IOException
- Specified by:
write
in class java.io.Writer
- 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
- Specified by:
flush
in class java.io.Writer
- Throws:
java.io.IOException
close
public void close()
throws java.io.IOException
- Specified by:
close
in interface java.io.Closeable
- Specified by:
close
in class java.io.Writer
- 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
.