Class IndentedWriter

  • All Implemented Interfaces:
    java.lang.AutoCloseable, AWriter, Closeable
    Direct Known Subclasses:
    IndentedLineBuffer

    public class IndentedWriter
    extends AWriterBase
    implements AWriter, Closeable
    A writer that records what the current indentation level is, and uses that to insert a prefix at each line. It can also insert line numbers at the beginning of lines.
    • Field Detail

      • stdout

        public static final IndentedWriter stdout
        Stdout wrapped in an IndentedWriter - no line numbers
      • stderr

        public static final IndentedWriter stderr
        Stderr wrapped in an IndentedWriter - no line numbers
    • Constructor Detail

      • IndentedWriter

        public IndentedWriter​(java.io.OutputStream outStream)
        Construct a UTF8 IndentedWriter around an OutputStream
      • IndentedWriter

        public IndentedWriter​(java.io.OutputStream outStream,
                              boolean withLineNumbers)
        Construct a UTF8 IndentedWriter around an OutputStream
    • Method Detail

      • clone

        public static IndentedWriter clone​(IndentedWriter other)
        Create an independent copy of the IndentedWriter. Changes to the configuration of the copy will not affect the original IndentedWriter. This include indentation level.
        Row and column counters are reset.
        Indent is initially. zero.
        They do share the underlying output Writer.
        Parameters:
        other -
        Returns:
        IndentedWriter
      • print

        public void print​(java.lang.String str)
        Specified by:
        print in interface AWriter
      • printf

        public void printf​(java.lang.String formatStr,
                           java.lang.Object... args)
        Specified by:
        printf in interface AWriter
      • print

        public void print​(char ch)
        Specified by:
        print in interface AWriter
      • print

        public void print​(java.lang.Object obj)
      • println

        public void println​(java.lang.String str)
        Specified by:
        println in interface AWriter
      • println

        public void println​(char ch)
      • println

        public void println​(java.lang.Object obj)
      • println

        public void println()
        Specified by:
        println in interface AWriter
      • print

        public void print​(char[] cbuf)
        Specified by:
        print in interface AWriter
      • print

        public void print​(java.lang.String s,
                          int n)
        Print a string N times
      • print

        public void print​(char ch,
                          int n)
        Print a char N times
      • newline

        public void newline()
      • ensureStartOfLine

        public void ensureStartOfLine()
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface AWriter
        Specified by:
        close in interface Closeable
      • flush

        public void flush()
        Specified by:
        flush in interface AWriter
      • pad

        public void pad()
        Pad to the indent (if we are before it)
      • pad

        public void pad​(int col)
        Pad to a given number of columns EXCLUDING the indent.
        Parameters:
        col - Column number (first column is 1).
      • pad

        public void pad​(int col,
                        boolean absoluteColumn)
        Pad to a given number of columns maybe including the indent.
        Parameters:
        col - Column number (first column is 1).
        absoluteColumn - Whether to include the indent
      • getRow

        public int getRow()
        Get row/line (counts from 1)
      • getCol

        public int getCol()
        Get the absolute column. This is the location where the next character on the line will be printed. The IndentedWriter may not yet have padded to this place.
      • getAbsoluteIndent

        public int getAbsoluteIndent()
        Get indent from the left hand edge
      • setAbsoluteIndent

        public void setAbsoluteIndent​(int x)
        Set indent from the left hand edge
      • getCurrentOffset

        public int getCurrentOffset()
        Position past current indent
      • hasLineNumbers

        public boolean hasLineNumbers()
      • setLineNumbers

        public void setLineNumbers​(boolean lineNumbers)
      • getEndOfLineMarker

        public java.lang.String getEndOfLineMarker()
      • setEndOfLineMarker

        public void setEndOfLineMarker​(java.lang.String marker)
        Set the marker included at end of line - set to null for "none". Usually used for debugging.
      • inFlatMode

        public boolean inFlatMode()
        Flat mode - print without NL, for a more compact representation
      • setFlatMode

        public void setFlatMode​(boolean flatMode)
        Flat mode - print without NL, for a more compact representation
      • getFlushOnNewline

        public boolean getFlushOnNewline()
        Flush on newline
      • setFlushOnNewline

        public void setFlushOnNewline​(boolean flushOnNewline)
        Flush on newline in this code. This is set for stdout and stderr but not by default otherwise. The underlying output, if it is a PrintStream may also have a flush on newline as well (e.g System.out).
      • getPadChar

        public char getPadChar()
      • setPadChar

        public void setPadChar​(char ch)
      • getPadString

        public java.lang.String getPadString()
      • setPadString

        public void setPadString​(java.lang.String str)
      • getLinePrefix

        public java.lang.String getLinePrefix()
        Initial string printed at the start of each line : defaults to no string.
      • setLinePrefix

        public void setLinePrefix​(java.lang.String str)
        Set the initial string printed at the start of each line.
      • incIndent

        public void incIndent()
      • incIndent

        public void incIndent​(int x)
      • decIndent

        public void decIndent()
      • decIndent

        public void decIndent​(int x)
      • setUnitIndent

        public void setUnitIndent​(int x)
      • getUnitIndent

        public int getUnitIndent()
      • atLineStart

        public boolean atLineStart()
      • getNumberWidth

        public int getNumberWidth()
        Width of the number field
      • setNumberWidth

        public void setNumberWidth​(int widthOfNumbers)
        Set the width of the number field. There is also a single space after the number not included in this setting.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object