Package de.xima.fc.common.io
Class TrimmingWriter
- java.lang.Object
-
- java.io.Writer
-
- de.xima.fc.common.io.TrimmingWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public final class TrimmingWriter extends Writer
A writer that trims leading and trailing characters from the content before writing them to the underlying writer.Note:
Flushingthis writer does not flush characters that are still in the lookahead buffer, as they have not yet been processed for whether they need to be trimmed. Content may remain buffered and unflushed, until either a subsequent non-trimmable character is written or the writer is closed.This writer is not thread-safe and must be synchronized externally if used by multiple threads.
- Since:
- 8.5.4
-
-
Constructor Summary
Constructors Constructor Description TrimmingWriter(Writer writer, char[] trimChars)Creates a new writer that wraps the given writer and trims leading and trailing characters from the content before writing them to the underlying writer.TrimmingWriter(Writer writer, String trimChars)Creates a new writer that wraps the given writer and trims leading and trailing characters from the content before writing them to the underlying writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()voidwrite(char[] cbuf, int off, int len)
-
-
-
Constructor Detail
-
TrimmingWriter
public TrimmingWriter(Writer writer, String trimChars)
Creates a new writer that wraps the given writer and trims leading and trailing characters from the content before writing them to the underlying writer.- Parameters:
writer- The underlying writer to write totrimChars- The characters to trim from the start and end content. If null or empty, no characters will be trimmed.
-
TrimmingWriter
public TrimmingWriter(Writer writer, char[] trimChars)
Creates a new writer that wraps the given writer and trims leading and trailing characters from the content before writing them to the underlying writer.- Parameters:
writer- The underlying writer to write totrimChars- The characters to trim from the start and end content. If null or empty, no characters will be trimmed.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
-