Class IndentedWriter

java.lang.Object
org.apache.jena.atlas.io.AWriterBase
org.apache.jena.atlas.io.IndentedWriter
All Implemented Interfaces:
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 Details

    • 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 Details

    • IndentedWriter

      public IndentedWriter(OutputStream outStream)
      Construct a UTF8 IndentedWriter around an OutputStream
    • IndentedWriter

      public IndentedWriter(OutputStream outStream, boolean withLineNumbers)
      Construct a UTF8 IndentedWriter around an OutputStream
  • Method Details

    • 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
    • clone

      public IndentedWriter clone()
    • print

      public void print(String str)
      Specified by:
      print in interface AWriter
    • printf

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

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

      public void print(Object obj)
    • println

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

      public void println(char ch)
    • println

      public void println(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(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()
    • atLineStart

      public boolean atLineStart()
    • close

      public void close()
      Specified by:
      close in interface 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.
    • incIndent

      public void incIndent()
    • incIndent

      public void incIndent(int x)
    • decIndent

      public void decIndent()
    • decIndent

      public void decIndent(int x)
    • getCurrentOffset

      public int getCurrentOffset()
      Position past current indent
    • getAbsoluteIndent

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

      public void setAbsoluteIndent(int x)
      Set indent from the left hand edge. Returns this.
    • hasLineNumbers

      public boolean hasLineNumbers()
    • setLineNumbers

      public void setLineNumbers(boolean lineNumbers)
    • getEndOfLineMarker

      public String getEndOfLineMarker()
    • setEndOfLineMarker

      public void setEndOfLineMarker(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 String getPadString()
    • setPadString

      public void setPadString(String str)
    • getLinePrefix

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

      public void setLinePrefix(String str)
      Set the initial string printed at the start of each line.
    • getUnitIndent

      public int getUnitIndent()
    • setUnitIndent

      public void setUnitIndent(int x)
    • 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 String toString()
      Overrides:
      toString in class Object