public class IndentWriter
extends Object
Writes that prefixes all lines with
a configurable number of spaces and
can be converted to a string once all
content has been written.
-
Field Summary
Fields
private static final char[]
Buffer of white space characters for copying.
The context of this writer (all written lines).
private int
The current indent (in spaces).
private boolean
True if the next write call is the
start of a new line and should thus
be prefixed with spaces.
-
Constructor Summary
Constructors
Constructs a new indent writer
with an indent of 0.
Constructs a new indent writer
with the given indent.
-
Method Summary
void
Decreases the current indent by the given
number of spaces.
int
Gets the current writer indent.
void
Increases the current indent by the given
number of spaces.
void
Adds the given integer to this writer.
void
Adds the given string to this writer.
void
void
Decreases the current indent by the given
amount and then adds the given string to
this writer and adds a line break.
void
Adds the given string to this writer and
adds a line break.
void
Adds the given string to this writer and
adds a line break.
void
Sets the indent to the given number of spaces.
-
Field Details
-
BUFFER
private static final char[] BUFFER
Buffer of white space characters for copying.
-
content
The context of this writer (all written lines).
-
indent
private int indent
The current indent (in spaces).
-
newLine
private boolean newLine
True if the next write call is the
start of a new line and should thus
be prefixed with spaces.
-
Constructor Details
-
IndentWriter
public IndentWriter()
Constructs a new indent writer
with an indent of 0.
- See Also:
-
-
IndentWriter
public IndentWriter(int indent)
Constructs a new indent writer
with the given indent.
- Parameters:
indent
- The writer indent.
-
Method Details
-
getIndent
public int getIndent()
Gets the current writer indent.
- Returns:
- The indent (in spaces).
-
print
Adds the given string to this writer.
- Parameters:
str
- The string to print.
-
println
public void println(String str)
Adds the given string to this writer and
adds a line break.
- Parameters:
str
- The string to print.
-
println
public void println()
Writes a line break.
-
println
public void println(String str,
int indentIncrease)
Adds the given string to this writer and
adds a line break. After that increases
the current indent by the given amount.
- Parameters:
str
- The string to print.
indentIncrease
- The amount to increase
the indent by.
-
println
public void println(int indentDecrease,
String str)
Decreases the current indent by the given
amount and then adds the given string to
this writer and adds a line break.
- Parameters:
str
- The string to print.
indentDecrease
- The amount to decrease
the indent by.
-
increaseIndent
public void increaseIndent(int n)
Increases the current indent by the given
number of spaces.
- Parameters:
n
- The number of spaces to
increase the indent by.
-
decreaseIndent
public void decreaseIndent(int n)
Decreases the current indent by the given
number of spaces.
- Parameters:
n
- The number of spaces to
decrease the indent by.
-
setIndent
public void setIndent(int n)
Sets the indent to the given number of spaces.
- Parameters:
n
- The new indent.
-
print
public void print(int i)
Adds the given integer to this writer.
- Parameters:
i
- The integer to print.
-