Class IndentingWriter

java.lang.Object
java.io.Writer
org.eclipse.rdf4j.common.io.IndentingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class IndentingWriter extends Writer
A writer that adds indentation to written text.
Author:
Arjohn Kampman
  • Field Details

    • out

      protected Writer out
      The underlying writer.
    • indentationLevel

      protected int indentationLevel
      The current indentation level, i.e. the number of tabs to indent a start or end tag.
  • Constructor Details

    • IndentingWriter

      public IndentingWriter(Writer out)
  • Method Details

    • setIndentationString

      public void setIndentationString(String indentString)
      Sets the string that should be used for indentation. The default indentation string is a tab character.
      Parameters:
      indentString - The indentation string, e.g. a tab or a number of spaces.
    • getIndentationString

      public String getIndentationString()
      Gets the string used for indentation.
      Returns:
      the indentation string.
    • getIndentationLevel

      public int getIndentationLevel()
      Get the indentation level (number of tabs or indentation string).
      Returns:
      level as an integer
    • setIndentationLevel

      public void setIndentationLevel(int indentationLevel)
      Set indentation level (number of tabs or indentation string).
      Parameters:
      indentationLevel - level as an integer
    • getCharactersSinceEOL

      public int getCharactersSinceEOL()
      Get the number of characters read since end-of-line.
      Returns:
      number of characters
    • increaseIndentation

      public void increaseIndentation()
      Increase indentation level by 1.
    • decreaseIndentation

      public void decreaseIndentation()
      Decrease indentation level by 1.
    • writeEOL

      public void writeEOL() throws IOException
      Writes an end-of-line character sequence and triggers the indentation for the text written on the next line.
      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
    • flush

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

      public void write(String str, int off, int len) throws IOException
      Overrides:
      write in class Writer
      Throws:
      IOException
    • write

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