phonebill.util
Class Out

java.lang.Object
  |
  +--phonebill.util.Out

public class Out
extends java.lang.Object

This class provides output capabilities. The underlying mechanism uses PrintWriters with autoflushing.


Field Summary
protected static java.text.NumberFormat currencyFormatter
          The currency Formatter
protected static java.text.DateFormat dateFormatter
          The date Formatter
protected static java.io.PrintWriter debug
          The writer of debugging messages.
protected static int debugLevel
          The level of debugging output.
static java.lang.String indent
          The standard indentation string.
protected static boolean mustCloseDebug
          Indicates whether or not we are supposed to close the debugging writer.
protected static boolean mustCloseOutput
          Indicates whether or not we are supposed to close the output writer.
static java.lang.String newLineChar
          The system dependent newline character.
protected static java.text.NumberFormat numberFormatter
          The number Formatter
protected static java.io.PrintWriter output
          The writer of output messages.
 
Constructor Summary
private Out()
          Constructs a new Out object.
 
Method Summary
static void cleanup()
          Clean up loose ends.
static void debug(int level, java.lang.String message)
          Writes a debugging message on a whole line if the current debugLevel permits it.
static void debug(java.lang.Throwable thrown)
          Writes the stack trace for thrown as a debugging message ignoring the current debugLevel.
static java.text.NumberFormat getCurrencyFormat()
          Return a general purpose number formatter.
static java.text.DateFormat getDateFormat()
          Return a general purpose date formatter.
static int getDebugLevel()
          Return the current debugging level.
static java.text.NumberFormat getNumberFormat()
          Return a general purpose currency formatter.
static void print(java.lang.String message)
          Writes an output message without linebreak.
static void println()
          Writes a linebreak on the current output writer.
static void println(java.lang.String message)
          Writes an output message on a whole line.
static boolean setDebug(java.io.OutputStream out)
          Set the writer of debugging messages.
static boolean setDebug(java.io.OutputStream out, boolean mustClose)
          Set the writer of debugging messages.
static void setDebugLevel(int newLevel)
          Set the upper limit on debugging messages.
static boolean setPrint(java.io.OutputStream out)
          Set the writer of output messages.
static boolean setPrint(java.io.OutputStream out, boolean mustClose)
          Set the writer of output messages.
static boolean willCloseDebug()
          Return whether the current debugging writer will be closed automatically.
static boolean willCloseOutput()
          Return whether the current output writer will be closed automatically.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

newLineChar

public static final java.lang.String newLineChar
The system dependent newline character.

indent

public static final java.lang.String indent
The standard indentation string.

dateFormatter

protected static final java.text.DateFormat dateFormatter
The date Formatter

numberFormatter

protected static final java.text.NumberFormat numberFormatter
The number Formatter

currencyFormatter

protected static final java.text.NumberFormat currencyFormatter
The currency Formatter

debugLevel

protected static int debugLevel
The level of debugging output. High numbers indicate more detail.

debug

protected static java.io.PrintWriter debug
The writer of debugging messages. Default is System.err with autoflushing.

mustCloseDebug

protected static boolean mustCloseDebug
Indicates whether or not we are supposed to close the debugging writer. This is useful when using System.out since it may not be closed while the program is running.

output

protected static java.io.PrintWriter output
The writer of output messages. Default is System.out with autoflushing.

mustCloseOutput

protected static boolean mustCloseOutput
Indicates whether or not we are supposed to close the output writer. This is useful when using System.out since it may not be closed while the program is running.
Constructor Detail

Out

private Out()
     throws java.lang.UnsupportedOperationException
Constructs a new Out object. Not supposed to be used since everything is static.
Throws:
java.lang.UnsupportedOperationException - if it is used
Method Detail

debug

public static void debug(int level,
                         java.lang.String message)
Writes a debugging message on a whole line if the current debugLevel permits it.
Parameters:
level - The level of this debugging message. High numbers are more detailed.
message - The message to write.

debug

public static void debug(java.lang.Throwable thrown)
Writes the stack trace for thrown as a debugging message ignoring the current debugLevel.
Parameters:
thrown - The Throwable to write.

print

public static void print(java.lang.String message)
Writes an output message without linebreak.
Parameters:
message - The message to write.

println

public static void println(java.lang.String message)
Writes an output message on a whole line.
Parameters:
message - The message to write.

println

public static void println()
Writes a linebreak on the current output writer.

getDebugLevel

public static int getDebugLevel()
Return the current debugging level.
Returns:
the number representing the current level of debugging.

willCloseDebug

public static boolean willCloseDebug()
Return whether the current debugging writer will be closed automatically.
Returns:
true if it close() will be called on the debugging writer when it is replaced.

willCloseOutput

public static boolean willCloseOutput()
Return whether the current output writer will be closed automatically.
Returns:
true if it close() will be called on the output writer when it is replaced.

getDateFormat

public static java.text.DateFormat getDateFormat()
Return a general purpose date formatter.
Returns:
the default date formatter
See Also:
DateFormat.getInstance()

getCurrencyFormat

public static java.text.NumberFormat getCurrencyFormat()
Return a general purpose number formatter.
Returns:
the default number formatter
See Also:
NumberFormat.getInstance()

getNumberFormat

public static java.text.NumberFormat getNumberFormat()
Return a general purpose currency formatter.
Returns:
the default currency formatter
See Also:
NumberFormat.getCurrencyInstance()

setDebugLevel

public static void setDebugLevel(int newLevel)
Set the upper limit on debugging messages.
Parameters:
newLevel - The limit to use. A high number means more messages.

setDebug

public static boolean setDebug(java.io.OutputStream out)
Set the writer of debugging messages. The old one is closed if willCloseDebug() returns true.
Parameters:
out - The new OutputStream to use for debugging messages.
Returns:
true if future debug messages will be written to out.

setDebug

public static boolean setDebug(java.io.OutputStream out,
                               boolean mustClose)
Set the writer of debugging messages. The old one is closed if willCloseDebug() returns true.
Parameters:
out - The new OutputStream to use for debugging messages.
mustClose - if true, out will be closed automatically on replacement.
Returns:
true if future debug messages will be written to out.

setPrint

public static boolean setPrint(java.io.OutputStream out)
Set the writer of output messages. The old one is closed if willCloseOutput() returns true.
Parameters:
out - The new OutputStream to use for output messages.
Returns:
true if future output messages will be written to out.

setPrint

public static boolean setPrint(java.io.OutputStream out,
                               boolean mustClose)
Set the writer of output messages. The old one is closed if willCloseOutput() returns true.
Parameters:
out - The new OutputStream to use for output messages.
mustClose - if true, out will be closed automatically on replacement.
Returns:
true if future output messages will be written to out.

cleanup

public static void cleanup()
Clean up loose ends. This method should be called at the end of an apps lifetime.