org.apache.jena.atlas.io
Class IndentedWriter

java.lang.Object
  extended by org.apache.jena.atlas.io.AWriterBase
      extended by org.apache.jena.atlas.io.IndentedWriter
All Implemented Interfaces:
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 Summary
static IndentedWriter stderr
          Stderr wrapped in an IndentedWriter - no line numbers
static IndentedWriter stdout
          Stdout wrapped in an IndentedWriter - no line numbers
 
Constructor Summary
IndentedWriter(OutputStream outStream)
          Construct a UTF8 IndentedWriter around an OutputStream
IndentedWriter(OutputStream outStream, boolean withLineNumbers)
          Construct a UTF8 IndentedWriter around an OutputStream
 
Method Summary
 boolean atLineStart()
           
 void close()
           
 void decIndent()
           
 void decIndent(int x)
           
 void ensureStartOfLine()
           
 void flush()
           
 int getAbsoluteIndent()
           
 int getCol()
          Get the absolute column.
 int getCurrentOffset()
          Position past current indent
 String getEndOfLineMarker()
           
 boolean getFlushOnNewline()
          Flush on newline
 int getIndent()
          Deprecated. Use getAbsoluteIndent()
 char getPadChar()
           
 String getPadString()
           
 int getRow()
          Get row/line (counts from 1)
 int getUnitIndent()
           
 boolean hasLineNumbers()
           
 void incIndent()
           
 void incIndent(int x)
           
 boolean inFlatMode()
          Flat mode - print without NL, for a more compact representation - depends on caller
 void newline()
           
 void pad()
          Pad to the indent (if we are before it)
 void pad(int col)
          Pad to a given number of columns EXCLUDING the indent.
 void pad(int col, boolean absoluteColumn)
          Pad to a given number of columns maybe including the indent.
 void print(char ch)
           
 void print(char[] cbuf)
           
 void print(char ch, int n)
          Print a char N times
 void print(String str)
           
 void print(String s, int n)
          Print a string N times
 void printf(String formatStr, Object... args)
           
 void println()
           
 void println(char ch)
           
 void println(String str)
           
 void setAbsoluteIndent(int x)
           
 void setEndOfLineMarker(String marker)
          Set the marker included at end of line - set to null for "none".
 void setFlatMode(boolean flatMode)
           
 void setFlushOnNewline(boolean flushOnNewline)
           
 void setLineNumbers(boolean lineNumbers)
           
 void setPadChar(char ch)
           
 void setPadString(String str)
           
 void setUnitIndent(int x)
           
 String toString()
           
 
Methods inherited from class org.apache.jena.atlas.io.AWriterBase
write, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.jena.atlas.io.AWriter
write, write, write
 

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(OutputStream outStream)
Construct a UTF8 IndentedWriter around an OutputStream


IndentedWriter

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

Method Detail

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

println

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

println

public void println(char ch)

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()

close

public void close()
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 charcter on the line will be printed. The IndentedWriter may not yet have padded to this place.


getIndent

@Deprecated
public int getIndent()
Deprecated. Use getAbsoluteIndent()


getAbsoluteIndent

public int getAbsoluteIndent()

setAbsoluteIndent

public void setAbsoluteIndent(int x)

getCurrentOffset

public int getCurrentOffset()
Position past current indent


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 - depends on caller


setFlatMode

public void setFlatMode(boolean flatMode)

getFlushOnNewline

public boolean getFlushOnNewline()
Flush on newline


setFlushOnNewline

public void setFlushOnNewline(boolean flushOnNewline)

getPadChar

public char getPadChar()

setPadChar

public void setPadChar(char ch)

getPadString

public String getPadString()

setPadString

public void setPadString(String str)

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()

toString

public String toString()
Overrides:
toString in class Object


Licenced under the Apache License, Version 2.0