gov.nist.nlpir.irf.util
Class Support

java.lang.Object
  |
  +--gov.nist.nlpir.irf.util.Support

public final class Support
extends java.lang.Object

Provides miscellaneous methods to support some logging, access to system and runtime values, basic test mode functions, input methods, etc.

Version:
$Revision: 1.3 $
Author:
This software was produced by NIST, an agency of the U.S. government, and by statute is not subject to copyright in the United States. Recipients of this software assume all responsibilities associated with its operation, modification and maintenance.
See Also:
InfoObj

Field Summary
static int COARSE_TRACE
          Trace level constant
static char COMMENT_CHAR
          Everything beyond this sign is a comment that readLine() won't return.
static int DETAIL_TRACE
          Trace level constant
private static java.io.PrintWriter errorWriter
          Working PrintWriter for error message output
static java.lang.String fileSeparator
          Working local copy of file separator character
static int MEDIUM_TRACE
          Trace level constant
private static boolean outputState
          Flag indicating if debugging output is to be produced or not
private static java.io.PrintWriter outputWriter
          Working PrintWriter for use by the local methods print and println
private static boolean promptUser
          Flag indicating if the user is to be prompted for input
private static java.io.PrintWriter promptWriter
          Working PrintWriter for input prompt message output
private static java.lang.Runtime runtime
          Working instance of a Runtime object
private static java.io.BufferedReader sysRdr
          This reader should be the only one in the whole application listening to STDIN.
private static boolean testMode
          Flag indicating weather the application is in test mode
static int traceLevel
          Current trace level
private static java.io.PrintWriter traceWriter
          Working PrintWriter for trace message output
private static java.io.PrintWriter warningWriter
          Working PrintWriter for warning message output
 
Constructor Summary
Support()
           
 
Method Summary
static void debugOutputOn(boolean state)
          Sets state of debuging output.
static void errorMessage(java.lang.String message)
          Writes message to the error writer.
static boolean executeTrace(int level)
          Returns true if the supplied level would result in a trace message being generated.
static java.io.PrintWriter getErrorWriter()
          Gets the writer to which error messages are being directed.
static boolean getPromptUser()
          Gets value of promptUser.
static java.io.PrintWriter getPromptWriter()
          Gets the writer to which user prompts are being directed.
static boolean getTestMode()
          Gets the test mode.
static long getTimeInMillis()
          Gets time in milliseconds since midnight Jan 1st 1970.
static int getTraceLevel()
          Gets the maximum level of trace messages to be generated.
static java.io.PrintWriter getTraceWriter()
          Gets the writer to which trace messages are being directed.
static java.io.PrintWriter getWarningWriter()
          Gets the writer to which warning messages are being directed.
static void printTimestamp()
          Writes a timestamp to standard out.
static void printVM_MemoryStats()
          If printing debugging output, writes stats on memory usage by the Java virtual machine to standard out.
static void printVM_MemoryStatsWithGC()
          If printing debugging output, writes stats on memory usage by the Java virtual machine to standard out after calling gabage collection.
static boolean queryDebugOutput()
          Gets state of debugging output.
static java.lang.String readLine()
          This method mainly embeds BufferedReader.readLine() so that it doesn't raise any exception and, moreover, the entire application can share a unique reader based on the standard output, thus allowing to have, for example, command files.
NOTE ON COMMENTS: In order for those command files to be usable, a comment mechanism appeared.
static void requestGarbageCollection()
          Requests the garbage collector be run.
static void setErrorWriter(java.io.PrintStream stream)
          Sets the writer to a writer for the stream to which errors messages will be directed.
static void setErrorWriter(java.io.PrintWriter writer)
          Sets the writer to which errors messages will be directed.
static void setPrintWriter(java.io.PrintStream pStream)
          Sets output writer to a writer for the stream for debugging output.
static void setPrintWriter(java.io.PrintWriter writer)
          Sets output print writer for debugging output.
static void setPromptUser(boolean mode)
          Sets the promptUser.
static void setPromptWriter(java.io.PrintStream stream)
          Sets the writer to a writer for the stream to which user prompts will be directed.
static void setPromptWriter(java.io.PrintWriter writer)
          Sets the writer to which user prompts will be directed.
static void setTestMode(boolean mode)
          Sets the test mode.
static void setTraceLevel(int level)
          Sets the maximum level of trace messages to be generated.
static void setTraceWriter(java.io.PrintStream stream)
          Sets the writer to a writer for the stream to which trace messages will be directed.
static void setTraceWriter(java.io.PrintWriter writer)
          Sets the writer to which trace messages will be directed.
static void setWarningWriter(java.io.PrintStream stream)
          Sets the writer to a writer for the stream to which warning messages will be directed.
static void setWarningWriter(java.io.PrintWriter writer)
          Sets the writer to which warning messages will be directed.
static void traceMessage(int level, java.lang.String message)
          Writes message to the trace writer.
static void traceMessage(int level, java.lang.String s1, int v1, java.lang.String s2, int v2, java.lang.String s3, int v3)
          Writes message to the trace writer.
static void traceMessage(java.lang.String message)
          Writes message to the trace writer.
static void userPrompt(java.lang.String prompt)
          Writes the user prompt to the prompt writer.
static void userPromptLn(java.lang.String prompt)
          Writes the user prompt to the prompt writer.
static void warningMessage(java.lang.String message)
          Writes message to the warning stream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

COARSE_TRACE

public static final int COARSE_TRACE
Trace level constant

MEDIUM_TRACE

public static final int MEDIUM_TRACE
Trace level constant

DETAIL_TRACE

public static final int DETAIL_TRACE
Trace level constant

fileSeparator

public static final java.lang.String fileSeparator
Working local copy of file separator character

outputState

private static boolean outputState
Flag indicating if debugging output is to be produced or not

promptUser

private static boolean promptUser
Flag indicating if the user is to be prompted for input

testMode

private static boolean testMode
Flag indicating weather the application is in test mode

traceLevel

public static int traceLevel
Current trace level

errorWriter

private static java.io.PrintWriter errorWriter
Working PrintWriter for error message output

outputWriter

private static java.io.PrintWriter outputWriter
Working PrintWriter for use by the local methods print and println

promptWriter

private static java.io.PrintWriter promptWriter
Working PrintWriter for input prompt message output

traceWriter

private static java.io.PrintWriter traceWriter
Working PrintWriter for trace message output

warningWriter

private static java.io.PrintWriter warningWriter
Working PrintWriter for warning message output

runtime

private static java.lang.Runtime runtime
Working instance of a Runtime object

sysRdr

private static java.io.BufferedReader sysRdr
This reader should be the only one in the whole application listening to STDIN. Thus use of input files isn't prohibited anymore.

COMMENT_CHAR

public static final char COMMENT_CHAR
Everything beyond this sign is a comment that readLine() won't return.
Constructor Detail

Support

public Support()
Method Detail

setErrorWriter

public static final void setErrorWriter(java.io.PrintWriter writer)
Sets the writer to which errors messages will be directed.
Parameters:
writer - where error messages are to be sent.

setErrorWriter

public static final void setErrorWriter(java.io.PrintStream stream)
Sets the writer to a writer for the stream to which errors messages will be directed.
Parameters:
stream - where error messages are to be sent.

getErrorWriter

public static final java.io.PrintWriter getErrorWriter()
Gets the writer to which error messages are being directed.
Returns:
PrintWriter where error messages are being sent.

errorMessage

public static final void errorMessage(java.lang.String message)
Writes message to the error writer.
Parameters:
message - text to be printed on error writer.

setTraceLevel

public static final void setTraceLevel(int level)
Sets the maximum level of trace messages to be generated.
Parameters:
level - new maximum level of trace messages to be generated.

getTraceLevel

public static final int getTraceLevel()
Gets the maximum level of trace messages to be generated.
Returns:
the maximum level of trace messages to be generated.

executeTrace

public static final boolean executeTrace(int level)
Returns true if the supplied level would result in a trace message being generated.
Parameters:
level - to be checked against current trace level.
Returns:
true if the supplied level would result in a trace message being generated.

setTraceWriter

public static void setTraceWriter(java.io.PrintWriter writer)
Sets the writer to which trace messages will be directed.
Parameters:
writer - where trace messages are to be sent.

setTraceWriter

public static final void setTraceWriter(java.io.PrintStream stream)
Sets the writer to a writer for the stream to which trace messages will be directed.
Parameters:
stream - where trace messages are to be sent.

getTraceWriter

public static final java.io.PrintWriter getTraceWriter()
Gets the writer to which trace messages are being directed.
Returns:
PrintWriter where trace messages are being sent.

traceMessage

public static final void traceMessage(int level,
                                      java.lang.String s1,
                                      int v1,
                                      java.lang.String s2,
                                      int v2,
                                      java.lang.String s3,
                                      int v3)
Writes message to the trace writer.
Parameters:
level - at which this trace messages is to be sent.
message - text to be printed on trace writer.

traceMessage

public static final void traceMessage(int level,
                                      java.lang.String message)
Writes message to the trace writer.
Parameters:
level - at which this trace messages is to be sent.
message - text to be printed on trace writer.

traceMessage

public static void traceMessage(java.lang.String message)
Writes message to the trace writer.
Parameters:
message - text to be printed on trace writer.

setWarningWriter

public static final void setWarningWriter(java.io.PrintWriter writer)
Sets the writer to which warning messages will be directed.
Parameters:
writer - where warning messages are to be sent.

setWarningWriter

public static final void setWarningWriter(java.io.PrintStream stream)
Sets the writer to a writer for the stream to which warning messages will be directed.
Parameters:
stream - where warning messages are to be sent.

getWarningWriter

public static final java.io.PrintWriter getWarningWriter()
Gets the writer to which warning messages are being directed.
Returns:
Writer where warning messages are being sent.

warningMessage

public static final void warningMessage(java.lang.String message)
Writes message to the warning stream.
Parameters:
level - at which this warning messages is to be sent.
message - text to be printed on warning stream.

setTestMode

public static final void setTestMode(boolean mode)
Sets the test mode.
Parameters:
mode - test mode on/off.

getTestMode

public static final boolean getTestMode()
Gets the test mode.
Returns:
current test mode.

setPromptUser

public static final void setPromptUser(boolean mode)
Sets the promptUser.
Parameters:
promptUser - on/off.

getPromptUser

public static final boolean getPromptUser()
Gets value of promptUser.
Returns:
current value promptUser.

setPromptWriter

public static final void setPromptWriter(java.io.PrintWriter writer)
Sets the writer to which user prompts will be directed.
Parameters:
writer - where user prompt are to be sent.

setPromptWriter

public static final void setPromptWriter(java.io.PrintStream stream)
Sets the writer to a writer for the stream to which user prompts will be directed.
Parameters:
stream - where user prompts are to be sent.

getPromptWriter

public static final java.io.PrintWriter getPromptWriter()
Gets the writer to which user prompts are being directed.
Returns:
PrintWriter where user prompts are being sent.

userPrompt

public static final void userPrompt(java.lang.String prompt)
Writes the user prompt to the prompt writer.
Parameters:
message - text to be printed on prompt writer.

userPromptLn

public static final void userPromptLn(java.lang.String prompt)
Writes the user prompt to the prompt writer.
Parameters:
message - text to be printed on prompt writer.

debugOutputOn

public static final void debugOutputOn(boolean state)
Sets state of debuging output.
Parameters:
state - new state of debugging output, set to true to turn on debugging output, false to turn off.

queryDebugOutput

public static final boolean queryDebugOutput()
Gets state of debugging output.
Returns:
true if debugging output is on.

setPrintWriter

public static final void setPrintWriter(java.io.PrintWriter writer)
Sets output print writer for debugging output.
Parameters:
writer - print writer for debugging output

setPrintWriter

public static final void setPrintWriter(java.io.PrintStream pStream)
Sets output writer to a writer for the stream for debugging output.
Parameters:
pStream - print stream for debugging output

printTimestamp

public static final void printTimestamp()
Writes a timestamp to standard out.

getTimeInMillis

public static final long getTimeInMillis()
Gets time in milliseconds since midnight Jan 1st 1970.
Returns:
time in milliseconds

requestGarbageCollection

public static final void requestGarbageCollection()
Requests the garbage collector be run.

printVM_MemoryStats

public static final void printVM_MemoryStats()
If printing debugging output, writes stats on memory usage by the Java virtual machine to standard out.

printVM_MemoryStatsWithGC

public static final void printVM_MemoryStatsWithGC()
If printing debugging output, writes stats on memory usage by the Java virtual machine to standard out after calling gabage collection.

readLine

public static final java.lang.String readLine()
This method mainly embeds BufferedReader.readLine() so that it doesn't raise any exception and, moreover, the entire application can share a unique reader based on the standard output, thus allowing to have, for example, command files.
NOTE ON COMMENTS: In order for those command files to be usable, a comment mechanism appeared. Everything you type after the comment char is considered a comment and thus is not parsed. The comment sign is defined by COMMENT_CHAR:
See Also:
COMMENT_CHAR