grace.io
Class FormattedPrintWriter

java.lang.Object
  |
  +--java.io.Writer
        |
        +--java.io.PrintWriter
              |
              +--grace.io.PrintWriter
                    |
                    +--grace.io.FormattedPrintWriter

public class FormattedPrintWriter
extends PrintWriter

This class provides a PrintWriter that can be configured generally by a format String.

The formatting operation is as follows. A format string is dictates the way objects are formatted. It is composed of the subformat sections. Each format subsection is separated by a bar ('|') character. So the general format is:

format: header|begin-block|field|end-block

 

The header format is used only once, at the beginning of the object dump. It can be used to print one time only header information.

The begin-block format is used just before a sub object is printed. After using this format, the indent level is increased one level.

The field format is used for each field in the object. Formatting is recursive, so if a field is an object, a new sub block is started and the formatting continues recursively. If the field is a primitive value, it is printed simply.

The end-block format is used after a complete sub object has been formatted.

The syntax of the each subformat is as follows:


Fields inherited from class grace.io.PrintWriter
dateFormat
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FormattedPrintWriter(java.io.OutputStream stream)
           
FormattedPrintWriter(java.io.OutputStream stream, boolean autoFlush)
           
FormattedPrintWriter(java.io.Writer writer)
           
FormattedPrintWriter(java.io.Writer writer, boolean autoFlush)
           
 
Method Summary
 void beginList()
           
 void beginObject()
           
 void endList()
           
 void endObject()
           
protected  void indent()
           
protected  void newlineAndIndent()
           
 void printBeginBlock()
           
protected  void printBlocking(java.lang.String format)
          This formats the blocking of the object - that is the beginning and ending of the text that surrounds an object.
 void printEndBlock()
           
protected  void printField(Value value)
          This formats the object based on the fieldFormat string.
protected  void printNullObject()
           
protected  void printNullString()
           
 void separateListItems()
           
 void separateObjectItems()
           
 void setBeginBlockFormat(java.lang.String format)
           
 void setEndBlockFormat(java.lang.String format)
           
 void setFieldFormat(java.lang.String format)
           
 void setFormat(java.lang.String format)
          Uses the bar character to separate the beginBlock, field, and endBlock formats.
 void setFormat(java.lang.String header, java.lang.String beginBlock, java.lang.String field, java.lang.String endBlock)
          Sets the 4 parts of the format.
 void setHeaderFormat(java.lang.String format)
           
 
Methods inherited from class grace.io.PrintWriter
add, addPrintHandler, alreadyPrinted, arrayTypeName, autoFlush, beginString, endString, fieldAccessors, getPrintHandler, getPrintMethod, getPrintObjectsOnlyOnce, getPrintToHandler, prettyOutput, print, print, print, print, print, print, print, print, print, print, print, print, print, printListElementValue, printName, printQuoted, printType, printValue, printWithFieldAccessors, referenceNameOf, rememberAccessorsUsingFields, rememberAccessorsUsingGetMethods, rememberPrinted, rightmostName, setDateFormat, setPrettyOutput, setPrintObjectsOnlyOnce, shortenedTypeName
 
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, println, setError, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormattedPrintWriter

public FormattedPrintWriter(java.io.OutputStream stream)

FormattedPrintWriter

public FormattedPrintWriter(java.io.OutputStream stream,
                            boolean autoFlush)

FormattedPrintWriter

public FormattedPrintWriter(java.io.Writer writer)

FormattedPrintWriter

public FormattedPrintWriter(java.io.Writer writer,
                            boolean autoFlush)
Method Detail

setFormat

public void setFormat(java.lang.String format)
Uses the bar character to separate the beginBlock, field, and endBlock formats.

setFormat

public void setFormat(java.lang.String header,
                      java.lang.String beginBlock,
                      java.lang.String field,
                      java.lang.String endBlock)
Sets the 4 parts of the format. See the description of this class above for more information.

setHeaderFormat

public void setHeaderFormat(java.lang.String format)

setBeginBlockFormat

public void setBeginBlockFormat(java.lang.String format)

setFieldFormat

public void setFieldFormat(java.lang.String format)

setEndBlockFormat

public void setEndBlockFormat(java.lang.String format)

printField

protected void printField(Value value)
This formats the object based on the fieldFormat string.

This function parses the format:

  • %i - indent
  • %C - full classname
  • %c - shortened classname
  • %t - shortened JDK classname
  • %n - name
  • %v - value
  • %r - reference number of value
  • text
Overrides:
printField in class PrintWriter

printBlocking

protected void printBlocking(java.lang.String format)
This formats the blocking of the object - that is the beginning and ending of the text that surrounds an object.

This function parses the format:

  • %i - indent
  • %c - classname
  • %n - name
  • %v - value
  • text

printBeginBlock

public void printBeginBlock()

printEndBlock

public void printEndBlock()

indent

protected void indent()

newlineAndIndent

protected void newlineAndIndent()

beginList

public void beginList()
Overrides:
beginList in class PrintWriter

endList

public void endList()
Overrides:
endList in class PrintWriter

beginObject

public void beginObject()
Overrides:
beginObject in class PrintWriter

endObject

public void endObject()
Overrides:
endObject in class PrintWriter

separateListItems

public void separateListItems()

separateObjectItems

public void separateObjectItems()

printNullString

protected void printNullString()
Overrides:
printNullString in class PrintWriter

printNullObject

protected void printNullObject()
Overrides:
printNullObject in class PrintWriter