Package org.omnifaces.io
Class ResettableBufferedWriter
- java.lang.Object
-
- java.io.Writer
-
- org.omnifaces.io.ResettableBufferedWriter
-
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
,ResettableBuffer
public class ResettableBufferedWriter extends 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 byisResettable()
.- Author:
- Bauke Scholtz
- See Also:
ResettableBufferedOutputStream
-
-
Constructor Summary
Constructors Constructor Description ResettableBufferedWriter(Writer writer, int bufferSize, 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
-
-
-
Constructor Detail
-
ResettableBufferedWriter
public ResettableBufferedWriter(Writer writer, int bufferSize, 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.
-
-
Method Detail
-
write
public void write(char[] chars, int offset, int length) throws IOException
- Specified by:
write
in classWriter
- Throws:
IOException
-
reset
public void reset()
Description copied from interface:ResettableBuffer
Perform a buffer reset.- Specified by:
reset
in interfaceResettableBuffer
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- 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
.
-
-