Package org.apache.jena.atlas.io
Class IndentedWriter
- java.lang.Object
-
- org.apache.jena.atlas.io.AWriterBase
-
- org.apache.jena.atlas.io.IndentedWriter
-
- 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
Fields Modifier and Type Field Description static IndentedWriterstderrStderr wrapped in an IndentedWriter - no line numbersstatic IndentedWriterstdoutStdout wrapped in an IndentedWriter - no line numbers
-
Constructor Summary
Constructors Constructor Description IndentedWriter(java.io.OutputStream outStream)Construct a UTF8 IndentedWriter around an OutputStreamIndentedWriter(java.io.OutputStream outStream, boolean withLineNumbers)Construct a UTF8 IndentedWriter around an OutputStream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanatLineStart()static IndentedWriterclone(IndentedWriter other)Create an independent copy of theIndentedWriter.voidclose()voiddecIndent()voiddecIndent(int x)voidensureStartOfLine()voidflush()intgetAbsoluteIndent()Get indent from the left hand edgeintgetCol()Get the absolute column.intgetCurrentOffset()Position past current indentjava.lang.StringgetEndOfLineMarker()booleangetFlushOnNewline()Flush on newlinejava.lang.StringgetLinePrefix()Initial string printed at the start of each line : defaults to no string.intgetNumberWidth()Width of the number fieldchargetPadChar()java.lang.StringgetPadString()intgetRow()Get row/line (counts from 1)intgetUnitIndent()booleanhasLineNumbers()voidincIndent()voidincIndent(int x)booleaninFlatMode()Flat mode - print without NL, for a more compact representationvoidnewline()voidpad()Pad to the indent (if we are before it)voidpad(int col)Pad to a given number of columns EXCLUDING the indent.voidpad(int col, boolean absoluteColumn)Pad to a given number of columns maybe including the indent.voidprint(char ch)voidprint(char[] cbuf)voidprint(char ch, int n)Print a char N timesvoidprint(java.lang.Object obj)voidprint(java.lang.String str)voidprint(java.lang.String s, int n)Print a string N timesvoidprintf(java.lang.String formatStr, java.lang.Object... args)voidprintln()voidprintln(char ch)voidprintln(java.lang.Object obj)voidprintln(java.lang.String str)voidsetAbsoluteIndent(int x)Set indent from the left hand edgevoidsetEndOfLineMarker(java.lang.String marker)Set the marker included at end of line - set to null for "none".voidsetFlatMode(boolean flatMode)Flat mode - print without NL, for a more compact representationvoidsetFlushOnNewline(boolean flushOnNewline)Flush on newline in this code.voidsetLineNumbers(boolean lineNumbers)voidsetLinePrefix(java.lang.String str)Set the initial string printed at the start of each line.voidsetNumberWidth(int widthOfNumbers)Set the width of the number field.voidsetPadChar(char ch)voidsetPadString(java.lang.String str)voidsetUnitIndent(int x)java.lang.StringtoString()-
Methods inherited from class org.apache.jena.atlas.io.AWriterBase
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
-
-
Method Detail
-
clone
public static IndentedWriter clone(IndentedWriter other)
Create an independent copy of theIndentedWriter. Changes to the configuration of the copy will not affect the originalIndentedWriter. This include indentation level.
Row and column counters are reset.
Indent is initially. zero.
They do share the underlying outputWriter.- Parameters:
other-- Returns:
- IndentedWriter
-
printf
public void printf(java.lang.String formatStr, java.lang.Object... args)
-
print
public void print(java.lang.Object obj)
-
println
public void println(char ch)
-
println
public void println(java.lang.Object obj)
-
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()
-
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)
-
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:
toStringin classjava.lang.Object
-
-