Class AppendableWriter<T extends java.lang.Appendable>

  • Type Parameters:
    T - The type of the Appendable wrapped by this AppendableWriter.
    All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class AppendableWriter<T extends java.lang.Appendable>
    extends java.io.Writer
    Writer implementation that writes the data to an Appendable Object.

    For example, can be used with a StringBuilder or StringBuffer.

    Since:
    2.7
    See Also:
    Appendable
    • Field Summary

      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      AppendableWriter​(T appendable)
      Constructs a new instance with the specified appendable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.Writer append​(char c)
      Appends the specified character to the underlying appendable.
      java.io.Writer append​(java.lang.CharSequence csq)
      Appends the specified character sequence to the underlying appendable.
      java.io.Writer append​(java.lang.CharSequence csq, int start, int end)
      Appends a subsequence of the specified character sequence to the underlying appendable.
      void close()
      Closes the stream.
      void flush()
      Flushes the stream.
      T getAppendable()
      Return the target appendable.
      void write​(char[] cbuf, int off, int len)
      Writes a portion of an array of characters to the underlying appendable.
      void write​(int c)
      Writes a character to the underlying appendable.
      void write​(java.lang.String str, int off, int len)
      Writes a portion of a String to the underlying appendable.
      • Methods inherited from class java.io.Writer

        nullWriter, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AppendableWriter

        public AppendableWriter​(T appendable)
        Constructs a new instance with the specified appendable.
        Parameters:
        appendable - the appendable to write to
    • Method Detail

      • append

        public java.io.Writer append​(char c)
                              throws java.io.IOException
        Appends the specified character to the underlying appendable.
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
        Parameters:
        c - the character to append
        Returns:
        this writer
        Throws:
        java.io.IOException - upon error
      • append

        public java.io.Writer append​(java.lang.CharSequence csq)
                              throws java.io.IOException
        Appends the specified character sequence to the underlying appendable.
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
        Parameters:
        csq - the character sequence to append
        Returns:
        this writer
        Throws:
        java.io.IOException - upon error
      • append

        public java.io.Writer append​(java.lang.CharSequence csq,
                                     int start,
                                     int end)
                              throws java.io.IOException
        Appends a subsequence of the specified character sequence to the underlying appendable.
        Specified by:
        append in interface java.lang.Appendable
        Overrides:
        append in class java.io.Writer
        Parameters:
        csq - the character sequence from which a subsequence will be appended
        start - the index of the first character in the subsequence
        end - the index of the character following the last character in the subsequence
        Returns:
        this writer
        Throws:
        java.io.IOException - upon error
      • close

        public void close()
                   throws java.io.IOException
        Closes the stream. This implementation does nothing.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
        Throws:
        java.io.IOException - upon error
      • flush

        public void flush()
                   throws java.io.IOException
        Flushes the stream. This implementation does nothing.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException - upon error
      • getAppendable

        public T getAppendable()
        Return the target appendable.
        Returns:
        the target appendable
      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
                   throws java.io.IOException
        Writes a portion of an array of characters to the underlying appendable.
        Specified by:
        write in class java.io.Writer
        Parameters:
        cbuf - an array with the characters to write
        off - offset from which to start writing characters
        len - number of characters to write
        Throws:
        java.io.IOException - upon error
      • write

        public void write​(int c)
                   throws java.io.IOException
        Writes a character to the underlying appendable.
        Overrides:
        write in class java.io.Writer
        Parameters:
        c - the character to write
        Throws:
        java.io.IOException - upon error
      • write

        public void write​(java.lang.String str,
                          int off,
                          int len)
                   throws java.io.IOException
        Writes a portion of a String to the underlying appendable.
        Overrides:
        write in class java.io.Writer
        Parameters:
        str - a string
        off - offset from which to start writing characters
        len - number of characters to write
        Throws:
        java.io.IOException - upon error