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: 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
  • Constructor Details

    • 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 to
      trimChars - 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 to
      trimChars - The characters to trim from the start and end content. If null or empty, no characters will be trimmed.
  • Method Details