info.aduna.io
Class IndentingWriter

java.lang.Object
  extended by java.io.Writer
      extended by info.aduna.io.IndentingWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class IndentingWriter
extends Writer

A writer that adds indentation to written text.

Author:
Arjohn Kampman

Field Summary
protected  int indentationLevel
          The current indentation level, i.e.
protected  Writer out
          The underlying writer.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
IndentingWriter(Writer out)
           
 
Method Summary
 void close()
           
 void decreaseIndentation()
           
 void flush()
           
 int getIndentationLevel()
           
 String getIndentationString()
          Gets the string used for indentation.
 void increaseIndentation()
           
 void setIndentationLevel(int indentationLevel)
           
 void setIndentationString(String indentString)
          Sets the string that should be used for indentation.
 void write(char[] cbuf, 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.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected 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.

Constructor Detail

IndentingWriter

public IndentingWriter(Writer out)
Method Detail

setIndentationString

public void setIndentationString(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 String getIndentationString()
Gets the string used for indentation.

Returns:
the indentation string.

getIndentationLevel

public int getIndentationLevel()

setIndentationLevel

public void setIndentationLevel(int indentationLevel)

increaseIndentation

public void increaseIndentation()

decreaseIndentation

public void decreaseIndentation()

writeEOL

public void writeEOL()
              throws IOException
Writes an end-of-line character sequence and triggers the indentation for the text written on the next line.

Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in class Writer
Throws:
IOException


Copyright © 2011 Aduna. All Rights Reserved.