Class StringBuilderWriter

java.lang.Object
java.io.Writer
org.apache.commons.io.output.StringBuilderWriter
All Implemented Interfaces:
Closeable, Flushable, Serializable, Appendable, AutoCloseable

public class StringBuilderWriter extends Writer implements Serializable
Writer implementation that outputs to a StringBuilder.

NOTE: This implementation, as an alternative to StringWriter, provides an un-synchronized implementation for better performance for use in a single thread. For safe usage with multiple Threads, a StringWriter should be used.

Deprecating Serialization

Serialization is deprecated and will be removed in 3.0.

Since:
2.0
See Also:
  • Constructor Details

  • Method Details

    • append

      public Writer append(char value)
      Appends a single character to this Writer.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer
      Parameters:
      value - The character to append
      Returns:
      This writer instance
    • append

      public Writer append(CharSequence value)
      Appends a character sequence to this Writer.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer
      Parameters:
      value - The character to append
      Returns:
      This writer instance
    • append

      public Writer append(CharSequence value, int start, int end)
      Appends a portion of a character sequence to the StringBuilder.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer
      Parameters:
      value - The character to append
      start - The index of the first character
      end - The index of the last character + 1
      Returns:
      This writer instance
    • close

      public void close()
      Closing this writer has no effect.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
    • flush

      public void flush()
      Flushing this writer has no effect.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
    • getBuilder

      Gets the underlying builder.
      Returns:
      The underlying builder
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      The contents of the String builder.
    • write

      public void write(char[] value, int offset, int length)
      Writes a portion of a character array to the StringBuilder.
      Specified by:
      write in class Writer
      Parameters:
      value - The value to write
      offset - The index of the first character
      length - The number of characters to write
    • write

      public void write(String value)
      Writes a String to the StringBuilder.
      Overrides:
      write in class Writer
      Parameters:
      value - The value to write