Class IndentingWriter

java.lang.Object
java.io.Writer
java.io.BufferedWriter
org.glassfish.rmic.IndentingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class IndentingWriter extends BufferedWriter
IndentingWriter is a BufferedWriter subclass that supports automatic indentation of lines of text written to the underlying Writer. Methods are provided for compact, convenient indenting, writing text, and writing lines in various combinations. WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    true if the next character written is the first on a line
    private int
    current number of spaces to prepend to lines
    private int
    number of spaces to change indent when indenting in or out
    private int
    number of spaces to convert into tabs.

    Fields inherited from class java.io.Writer

    lock
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new IndentingWriter that writes indented text to the given Writer.
    IndentingWriter(Writer out, int step)
    Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.
    IndentingWriter(Writer out, int step, int tabSize)
    Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step and tab size.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Check if an indent needs to be written before writing the next character.
    protected void
    Increase the current indent by the indent step.
    protected void
    Decrease the current indent by the indent step.
    void
    Write a line separator.
    void
    p(Object o)
    Write Object.
    void
    p(String s)
    Write string.
    void
    pI()
    Indent in.
    void
    pln()
    End current line.
    void
    Write Object; end current line.
    void
    Write string; end current line.
    void
    Write Object; end current line; indent in.
    void
    Write string; end current line; indent in.
    void
    pO()
    Indent out.
    void
    Indent out; write Object.
    void
    Indent out; write string.
    void
    Indent out; write Object; end current line.
    void
    Indent out; write string; end current line.
    void
    Indent out; write Object; end current line; indent in.
    void
    Indent out; write string; end current line; indent in.
    void
    write(char[] cbuf, int off, int len)
    Write a portion of an array of characters.
    void
    write(int c)
    Write a single character.
    void
    write(String s, int off, int len)
    Write a portion of a String.

    Methods inherited from class java.io.BufferedWriter

    close, flush

    Methods inherited from class java.io.Writer

    append, append, append, write, write

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • beginningOfLine

      private boolean beginningOfLine
      true if the next character written is the first on a line
    • currentIndent

      private int currentIndent
      current number of spaces to prepend to lines
    • indentStep

      private int indentStep
      number of spaces to change indent when indenting in or out
    • tabSize

      private int tabSize
      number of spaces to convert into tabs. Use MAX_VALUE to disable
  • Constructor Details

    • IndentingWriter

      public IndentingWriter(Writer out)
      Create a new IndentingWriter that writes indented text to the given Writer. Use the default indent step of four spaces.
    • IndentingWriter

      public IndentingWriter(Writer out, int step)
      Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.
    • IndentingWriter

      public IndentingWriter(Writer out, int step, int tabSize)
      Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step and tab size.
  • Method Details

    • write

      public void write(int c) throws IOException
      Write a single character.
      Overrides:
      write in class BufferedWriter
      Throws:
      IOException
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Write a portion of an array of characters.
      Overrides:
      write in class BufferedWriter
      Throws:
      IOException
    • write

      public void write(String s, int off, int len) throws IOException
      Write a portion of a String.
      Overrides:
      write in class BufferedWriter
      Throws:
      IOException
    • newLine

      public void newLine() throws IOException
      Write a line separator. The next character written will be preceded by an indent.
      Overrides:
      newLine in class BufferedWriter
      Throws:
      IOException
    • checkWrite

      protected void checkWrite() throws IOException
      Check if an indent needs to be written before writing the next character. The indent generation is optimized (and made consistent with certain coding conventions) by condensing groups of eight spaces into tab characters.
      Throws:
      IOException
    • indentIn

      protected void indentIn()
      Increase the current indent by the indent step.
    • indentOut

      protected void indentOut()
      Decrease the current indent by the indent step.
    • pI

      public void pI()
      Indent in.
    • pO

      public void pO()
      Indent out.
    • p

      public void p(String s) throws IOException
      Write string.
      Throws:
      IOException
    • pln

      public void pln() throws IOException
      End current line.
      Throws:
      IOException
    • pln

      public void pln(String s) throws IOException
      Write string; end current line.
      Throws:
      IOException
    • plnI

      public void plnI(String s) throws IOException
      Write string; end current line; indent in.
      Throws:
      IOException
    • pO

      public void pO(String s) throws IOException
      Indent out; write string.
      Throws:
      IOException
    • pOln

      public void pOln(String s) throws IOException
      Indent out; write string; end current line.
      Throws:
      IOException
    • pOlnI

      public void pOlnI(String s) throws IOException
      Indent out; write string; end current line; indent in. This method is useful for generating lines of code that both end and begin nested blocks, like "} else {".
      Throws:
      IOException
    • p

      public void p(Object o) throws IOException
      Write Object.
      Throws:
      IOException
    • pln

      public void pln(Object o) throws IOException
      Write Object; end current line.
      Throws:
      IOException
    • plnI

      public void plnI(Object o) throws IOException
      Write Object; end current line; indent in.
      Throws:
      IOException
    • pO

      public void pO(Object o) throws IOException
      Indent out; write Object.
      Throws:
      IOException
    • pOln

      public void pOln(Object o) throws IOException
      Indent out; write Object; end current line.
      Throws:
      IOException
    • pOlnI

      public void pOlnI(Object o) throws IOException
      Indent out; write Object; end current line; indent in. This method is useful for generating lines of code that both end and begin nested blocks, like "} else {".
      Throws:
      IOException