org.fudgemsg
Class FudgeMsgFormatter

java.lang.Object
  extended by org.fudgemsg.FudgeMsgFormatter

public class FudgeMsgFormatter
extends Object

Tool to pretty-print a Fudge message.


Field Summary
static int DEFAULT_INDENT
          The default indent (number of spaces)
 
Constructor Summary
FudgeMsgFormatter(PrintWriter writer)
          Creates a new pretty printer with a default indent.
FudgeMsgFormatter(PrintWriter writer, int indent)
          Creates a new pretty printer with a specific indent.
FudgeMsgFormatter(Writer writer)
          Creates a new pretty printer with a default indent.
FudgeMsgFormatter(Writer writer, int indent)
          Creates a new pretty printer with a specific indent.
 
Method Summary
 void format(FudgeFieldContainer msg)
          Pretty-prints a Fudge message.
protected  void format(FudgeFieldContainer msg, int depth)
          Pretty-prints a Fudge message with the given left hand indent.
protected  void format(FudgeField field, int index, int depth, String fieldSpec, int maxFieldSpecWidth, int maxTypeNameWidth)
          Lays out and writes a field description and value on a line to the output device.
protected  String getFieldSpec(FudgeField field, int index, int depth)
          Describes the fields name and ordinal.
protected  int getFieldSpecWidth(FudgeField field, int index, int depth)
          Calculates the length of a description (name + ordinal) of the field.
 int getIndent()
          Gets the size of the indent.
protected  String getTypeName(FudgeFieldType<?> type)
          Creates a string type name for a Fudge type.
 PrintWriter getWriter()
          Gets the target to output to.
static void outputToSystemOut(FudgeFieldContainer msg)
          Writes a Fudge message to System.out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INDENT

public static final int DEFAULT_INDENT
The default indent (number of spaces)

See Also:
Constant Field Values
Constructor Detail

FudgeMsgFormatter

public FudgeMsgFormatter(Writer writer)
Creates a new pretty printer with a default indent.

Parameters:
writer - the target to write to, not null

FudgeMsgFormatter

public FudgeMsgFormatter(PrintWriter writer)
Creates a new pretty printer with a default indent.

Parameters:
writer - the target to write to, not null

FudgeMsgFormatter

public FudgeMsgFormatter(Writer writer,
                         int indent)
Creates a new pretty printer with a specific indent.

Parameters:
writer - the target to write to, not null
indent - the number of spaces to use for indentation, not negative

FudgeMsgFormatter

public FudgeMsgFormatter(PrintWriter writer,
                         int indent)
Creates a new pretty printer with a specific indent.

Parameters:
writer - the target to write to, not null
indent - the number of spaces to use for indentation, not negative
Method Detail

outputToSystemOut

public static void outputToSystemOut(FudgeFieldContainer msg)
Writes a Fudge message to System.out.

Parameters:
msg - the message to write, not null

getWriter

public PrintWriter getWriter()
Gets the target to output to.

Returns:
the writer, not null

getIndent

public int getIndent()
Gets the size of the indent.

Returns:
number of spaces, not negative

format

public void format(FudgeFieldContainer msg)
Pretty-prints a Fudge message.

This outputs the message to the writer passed in the constructor.

Parameters:
msg - the message to write, null ignored

format

protected void format(FudgeFieldContainer msg,
                      int depth)
Pretty-prints a Fudge message with the given left hand indent.

This outputs the message to the writer passed in the constructor.

Parameters:
msg - the message to write, null ignored
depth - indentation level

getFieldSpecWidth

protected int getFieldSpecWidth(FudgeField field,
                                int index,
                                int depth)
Calculates the length of a description (name + ordinal) of the field.

Parameters:
field - the field to describe, not null
index - the offset index of the field within the message
depth - the indentation level
Returns:
the length in characters

format

protected void format(FudgeField field,
                      int index,
                      int depth,
                      String fieldSpec,
                      int maxFieldSpecWidth,
                      int maxTypeNameWidth)
Lays out and writes a field description and value on a line to the output device.

Parameters:
field - the field to describe, not null
index - the offset index of the field within the message
depth - the indentation level
fieldSpec - the field description (name + ordinal)
maxFieldSpecWidth - the maximum length (in characters) of all fieldSpecs within the message
maxTypeNameWidth - the maximum length (in characters) of all type names within the message

getFieldSpec

protected String getFieldSpec(FudgeField field,
                              int index,
                              int depth)
Describes the fields name and ordinal.

Parameters:
field - the field to describe
index - the offset index into the containing message
depth - the indentation level
Returns:
the description prefixed with the necessary indent

getTypeName

protected String getTypeName(FudgeFieldType<?> type)
Creates a string type name for a Fudge type.

Parameters:
type - the Fudge type
Returns:
the type name, not null


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0