classUtils.pack.util
Class IndentedPrintWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by classUtils.pack.util.IndentedPrintWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

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

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.
 void decIndentation(int level)
          Decrement the current indentation level of the given 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
append, append, append, checkError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, write, write
 
Methods inherited from class java.lang.Object
equals, 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

Overrides:
write in class java.io.PrintWriter

write

public void write(int c)
Write a character

Overrides:
write in class java.io.PrintWriter

write

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

Overrides:
write in class java.io.PrintWriter

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').

Overrides:
println in class java.io.PrintWriter