Class IndentedWriter


  • public class IndentedWriter
    extends java.lang.Object
    A stream writer keeping track of indentation. Prefixes strings given to it with the current indentation in form of spaces before writing them to the underlying Writer object.
    • Constructor Summary

      Constructors 
      Constructor Description
      IndentedWriter​(java.io.Writer out, int spacesPerIndent)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void decreaseIndent()
      Decreases the indentation one step.
      void increaseIndent()
      Increases the indentation one step.
      void write​(java.lang.String s)
      Writes a string with the current indentation.
      void writeLine​(java.lang.String s)
      Writes a string with the current indentation, followed by a newline.
      void writeLineNoIndent​(java.lang.String s)
      Writes a string without indentation, followed by a newline.
      void writeNoIndent​(java.lang.String s)
      Writes a string without indentation.
      • Methods inherited from class java.lang.Object

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

      • IndentedWriter

        public IndentedWriter​(java.io.Writer out,
                              int spacesPerIndent)
        Parameters:
        out - The stream in which to write
        spacesPerIndent - The number of spaces per indentation step
    • Method Detail

      • increaseIndent

        public void increaseIndent()
        Increases the indentation one step. Subsequent writes will receive more leading spaces.
      • decreaseIndent

        public void decreaseIndent()
        Decreases the indentation one step. Subsequent writes will receive fewer leading spaces. Does nothing if the indent would become negative.
      • write

        public void write​(java.lang.String s)
                   throws java.io.IOException
        Writes a string with the current indentation.
        Parameters:
        s - The string to write.
        Throws:
        java.io.IOException - Throws if the underlying Writer instance throws.
      • writeNoIndent

        public void writeNoIndent​(java.lang.String s)
                           throws java.io.IOException
        Writes a string without indentation.
        Parameters:
        s - The string to write
        Throws:
        java.io.IOException - Throws if the underlying Writer instance throws.
      • writeLine

        public void writeLine​(java.lang.String s)
                       throws java.io.IOException
        Writes a string with the current indentation, followed by a newline.
        Parameters:
        s - The string to write
        Throws:
        java.io.IOException - Throws if the underlying Writer instance throws.
      • writeLineNoIndent

        public void writeLineNoIndent​(java.lang.String s)
                               throws java.io.IOException
        Writes a string without indentation, followed by a newline.
        Parameters:
        s - The string to write
        Throws:
        java.io.IOException - Throws if the underlying Writer instance throws.