org.sadun.util
Class IndentedPrintWriter

java.lang.Object
  extended byjava.io.Writer
      extended byjava.io.PrintWriter
          extended byorg.sadun.util.IndentedPrintWriter

public class IndentedPrintWriter
extends java.io.PrintWriter

A PrintWriter which indents each line of text with a given character.

Version:
1.2
Author:
Cris Sadun

Field Summary
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
IndentedPrintWriter(java.io.OutputStream out)
          Create a new writer over the given stream, with the default indentation value and no autoflush.
IndentedPrintWriter(java.io.OutputStream out, boolean autoFlush)
          Create a new writer over the given stream, with the default indentation value.
IndentedPrintWriter(java.io.OutputStream out, int indent)
          Create a new writer over the given stream, with the given indentation value, and no autoflush.
IndentedPrintWriter(java.io.OutputStream out, int indent, boolean autoFlush)
          Create a new writer over the given stream, with the given indentation value.
IndentedPrintWriter(java.io.Writer w)
          Create a new writer over the given one, with the default indentation value, and no autoflush.
IndentedPrintWriter(java.io.Writer w, boolean autoFlush)
          Create a new writer over the given one, with the defaukt indentation value.
IndentedPrintWriter(java.io.Writer w, int indent)
          Create a new writer over the given one, with the given indentation value.
IndentedPrintWriter(java.io.Writer w, int indent, boolean autoFlush)
          Create a new writer over the given one, with the given indentation value.
 
Method Summary
 void decIndentation()
          Decrement the current indentation level. 0 is the minimum level.
 void decIndentation(int level)
          Decrement the current indentation level of the given level. 0 is the minimum level.
 int getIndentation()
          Return the current indentation level
 char getIndentationChar()
          Return the charachter used to indent to the given character
 void incIndentation()
          Increment the current indentation level.
 void incIndentation(int level)
          Increment the current indentation level of the given level.
 void println()
          Terminate the current line by writing the line separator string.
 void setIndentation(int indent)
          Sets the current indentation level
 void setIndentationChar(char c)
          Set the charachter used to indent to the given character
 void write(char[] buf, int off, int len)
          Write a portion of character array, of given length from a given offset
 void write(int c)
          Write a character
 void write(java.lang.String s, int off, int len)
          Write a substring of a string, of given length from a given offset
 
Methods inherited from class java.io.PrintWriter
checkError, close, flush, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, setError, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndentedPrintWriter

public IndentedPrintWriter(java.io.Writer w,
                           int indent)
Create a new writer over the given one, with the given indentation value. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
w - the writer wrapped by this IndentationPrintWriter
indent - the indentation level

IndentedPrintWriter

public IndentedPrintWriter(java.io.OutputStream out,
                           int indent,
                           boolean autoFlush)
Create a new writer over the given stream, with the given indentation value. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
out - the stream wrapped by this IndentationPrintWriter
indent - the indentation level
autoFlush - if true, the println() methods will flush the output buffer

IndentedPrintWriter

public IndentedPrintWriter(java.io.OutputStream out,
                           int indent)
Create a new writer over the given stream, with the given indentation value, and no autoflush. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
out - the stream wrapped by this IndentationPrintWriter
indent - the indentation level

IndentedPrintWriter

public IndentedPrintWriter(java.io.Writer w,
                           int indent,
                           boolean autoFlush)
Create a new writer over the given one, with the given indentation value. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
w - the writer wrapped by this IndentationPrintWriter
indent - the indentation level
autoFlush - if true, the println() methods will flush the output buffer

IndentedPrintWriter

public IndentedPrintWriter(java.io.Writer w)
Create a new writer over the given one, with the default indentation value, and no autoflush. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
w - the writer wrapped by this IndentationPrintWriter

IndentedPrintWriter

public IndentedPrintWriter(java.io.OutputStream out,
                           boolean autoFlush)
Create a new writer over the given stream, with the default indentation value. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
out - the stream wrapped by this IndentationPrintWriter
autoFlush - if true, the println() methods will flush the output buffer

IndentedPrintWriter

public IndentedPrintWriter(java.io.OutputStream out)
Create a new writer over the given stream, with the default indentation value and no autoflush. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
out - the stream wrapped by this IndentationPrintWriter

IndentedPrintWriter

public IndentedPrintWriter(java.io.Writer w,
                           boolean autoFlush)
Create a new writer over the given one, with the defaukt indentation value. The indentation charachter defaults to blank - use setIndentationChar() to set it differently if required.

Parameters:
w - the writer wrapped by this IndentationPrintWriter
autoFlush - if true, the println() methods will flush the output buffer
Method Detail

getIndentation

public int getIndentation()
Return the current indentation level

Returns:
the current indentation level

setIndentation

public void setIndentation(int indent)
Sets the current indentation level

Parameters:
indent - the desired indentation level

incIndentation

public void incIndentation(int level)
Increment the current indentation level of the given level.

Parameters:
level - the indentation level to be incremented

decIndentation

public void decIndentation(int level)
Decrement the current indentation level of the given level. 0 is the minimum level.

Parameters:
level - the indentation level to be reduced

incIndentation

public void incIndentation()
Increment the current indentation level.


decIndentation

public void decIndentation()
Decrement the current indentation level. 0 is the minimum level.


setIndentationChar

public void setIndentationChar(char c)
Set the charachter used to indent to the given character

Parameters:
c - the charachter to use for indentation

getIndentationChar

public char getIndentationChar()
Return the charachter used to indent to the given character

Returns:
the charachter to use for indentation

write

public void write(java.lang.String s,
                  int off,
                  int len)
Write a substring of a string, of given length from a given offset


write

public void write(int c)
Write a character


write

public void write(char[] buf,
                  int off,
                  int len)
Write a portion of character array, of given length from a given offset


println

public void println()
Terminate the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').