Class IndentingWriter

java.lang.Object
java.io.Writer
io.spring.initializr.generator.io.IndentingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class IndentingWriter extends Writer
A Writer with support for indenting.
Author:
Andy Wilkinson
  • Constructor Details

    • IndentingWriter

      public IndentingWriter(Writer out)
      Create a new instance with the specified writer using a default indent strategy of 4 spaces.
      Parameters:
      out - the writer to use
    • IndentingWriter

      public IndentingWriter(Writer out, Function<Integer,String> indentStrategy)
      Create a new instance with the specified writer and indent strategy.
      Parameters:
      out - the writer to use
      indentStrategy - a function that provides the ident to use based on a indentation level
  • Method Details

    • print

      public void print(String string)
      Write the specified text.
      Parameters:
      string - the content to write
    • println

      public void println(String string)
      Write the specified text and append a new line.
      Parameters:
      string - the content to write
    • println

      public void println()
      Write a new line.
    • indented

      public void indented(Runnable runnable)
      Increase the indentation level and execute the Runnable. Decrease the indentation level on completion.
      Parameters:
      runnable - the code to execute withing an extra indentation level
    • write

      public void write(char[] chars, int offset, int length)
      Specified by:
      write in class Writer
    • 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