Class TrimmingWriter
java.lang.Object
java.io.Writer
de.xima.fc.common.io.TrimmingWriter
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
A writer that trims leading and trailing characters from the content before writing them to the underlying writer.
Note: Flushing this 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
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTrimmingWriter(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
-
Constructor Details
-
TrimmingWriter
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
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 Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
write
- Specified by:
writein classWriter- Throws:
IOException
-