Class IndentingWriter

java.lang.Object
java.io.Writer
nl.talsmasoftware.umldoclet.rendering.indent.IndentingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class IndentingWriter extends Writer
Writer implementation that will indent each new line with a specified number of whitespace characters (four by default). The writing itself can be delegated to any other Writer implementation.
Author:
Sjoerd Talsma
  • Constructor Details

  • Method Details

    • wrap

      public static IndentingWriter wrap(Appendable delegate, Indentation indentation)
      Returns an indenting writer around the given delegate.
      If the delegate writer is already an indenting writer, it will simply be returned with the specified indentation.
      If the delegate writer is not yet an indending writer, a new indenting writer class will be created to wrap the delegate using the specified indentation.
      Parameters:
      delegate - The delegate to turn into an indenting writer.
      indentation - The indentation to use for the indenting writer (optional, specify null to use the default indentation).
      Returns:
      The indenting delegate writer.
      See Also:
      Indentation.DEFAULT
    • withIndentation

      public IndentingWriter withIndentation(Indentation newIndentation)
      Returns an indenting writer with the new indentation.

      Please note: Already written lines will not be modified to accomodate the new indentation.

      Parameters:
      newIndentation - The new indentation to apply to this writer (optional).
      Returns:
      Either this writer if the indentation is already correct, or a new IndentingWriter with the adapted indentation.
    • getIndentation

      protected Indentation getIndentation()
    • indent

      public IndentingWriter indent()
    • unindent

      public IndentingWriter unindent()
    • whitespace

      public IndentingWriter whitespace()
      Makes sure there is at least one whitespace character between the last charater and the next.

      This method attempts to avoid appending a whitespace character if it knows the last character was in fact a whitespace character. The whitespace character will also not be written until there are other characters that need to be written.

      Returns:
      Reference to this writer for chaining purposes.
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Specified by:
      write in class Writer
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object