Package org.eclipse.rdf4j.common.io
Class IndentingWriter
- java.lang.Object
-
- java.io.Writer
-
- org.eclipse.rdf4j.common.io.IndentingWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class IndentingWriter extends java.io.Writer
A writer that adds indentation to written text.
-
-
Field Summary
Fields Modifier and Type Field Description private int
charactersSinceEOL
Number of characters written since the last call towriteEOL()
protected int
indentationLevel
The current indentation level, i.e.private java.lang.String
indentationString
The string to use for indentation, e.g.private boolean
indentationWritten
Flag indicating whether indentation has been written for the current line.private static java.lang.String
LINE_SEPARATOR
The (platform-dependent) line separator.protected java.io.Writer
out
The underlying writer.
-
Constructor Summary
Constructors Constructor Description IndentingWriter(java.io.Writer out)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
decreaseIndentation()
Decrease indentation level by 1.void
flush()
int
getCharactersSinceEOL()
Get the number of characters read since end-of-line.int
getIndentationLevel()
Get the indentation level (number of tabs or indentation string).java.lang.String
getIndentationString()
Gets the string used for indentation.void
increaseIndentation()
Increase indentation level by 1.void
setIndentationLevel(int indentationLevel)
Set indentation level (number of tabs or indentation string).void
setIndentationString(java.lang.String indentString)
Sets the string that should be used for indentation.void
write(char[] cbuf, int off, int len)
void
write(java.lang.String str, int off, int len)
void
writeEOL()
Writes an end-of-line character sequence and triggers the indentation for the text written on the next line.
-
-
-
Field Detail
-
LINE_SEPARATOR
private static final java.lang.String LINE_SEPARATOR
The (platform-dependent) line separator.
-
out
protected java.io.Writer out
The underlying writer.
-
indentationLevel
protected int indentationLevel
The current indentation level, i.e. the number of tabs to indent a start or end tag.
-
indentationString
private java.lang.String indentationString
The string to use for indentation, e.g. a tab or a number of spaces.
-
indentationWritten
private boolean indentationWritten
Flag indicating whether indentation has been written for the current line.
-
charactersSinceEOL
private int charactersSinceEOL
Number of characters written since the last call towriteEOL()
-
-
Method Detail
-
setIndentationString
public void setIndentationString(java.lang.String indentString)
Sets the string that should be used for indentation. The default indentation string is a tab character.- Parameters:
indentString
- The indentation string, e.g. a tab or a number of spaces.
-
getIndentationString
public java.lang.String getIndentationString()
Gets the string used for indentation.- Returns:
- the indentation string.
-
getIndentationLevel
public int getIndentationLevel()
Get the indentation level (number of tabs or indentation string).- Returns:
- level as an integer
-
setIndentationLevel
public void setIndentationLevel(int indentationLevel)
Set indentation level (number of tabs or indentation string).- Parameters:
indentationLevel
- level as an integer
-
getCharactersSinceEOL
public int getCharactersSinceEOL()
Get the number of characters read since end-of-line.- Returns:
- number of characters
-
increaseIndentation
public void increaseIndentation()
Increase indentation level by 1.
-
decreaseIndentation
public void decreaseIndentation()
Decrease indentation level by 1.
-
writeEOL
public void writeEOL() throws java.io.IOException
Writes an end-of-line character sequence and triggers the indentation for the text written on the next line.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
- Throws:
java.io.IOException
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOException
- Specified by:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
-