org.tranche.httpd
Class Formatter

java.lang.Object
  extended by org.tranche.httpd.Formatter

public class Formatter
extends java.lang.Object

This class is a helper class to handle the formatting strings written either as an HTTP response, or to stdout, or to stderr.

Author:
Takis Papoulias

Field Summary
static boolean DEBUG
          Debug flag reserved for midium level of stdout vebrocity.
static boolean DEBUG_VERBOSE
          Debug flag reserver for a higher level of stdout vebrocity.
static boolean ECHO
          Flag for debugging an input stream.
static int READ_AHEAD
          Size to be used in marking an input stream.
 
Constructor Summary
Formatter()
           
 
Method Summary
static java.lang.String createPvFormat(HttpConstant param, HttpConstant value)
          Overloaded helper method for creating a HTTP proper response for a param value pair.
static java.lang.String createPvFormat(HttpConstant param, int value)
          Overloaded helper method for creating a HTTP proper response for a param value pair.
static java.lang.String createStatusLine(HttpConstant statusId, java.lang.String msg)
          Helper method for creating a properly formatted status line for the response.
static void printToErrLn(java.lang.Class caller, java.lang.String methodName, java.lang.String msg, java.lang.String data)
          Helper method that prints to the stderr details about a failure.
static void printToOutLn(java.lang.String msg)
          Helper method that prints to stdout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
Debug flag reserved for midium level of stdout vebrocity.

See Also:
Constant Field Values

DEBUG_VERBOSE

public static final boolean DEBUG_VERBOSE
Debug flag reserver for a higher level of stdout vebrocity.

See Also:
Constant Field Values

ECHO

public static final boolean ECHO
Flag for debugging an input stream. Usually used to activate a block of code that marks an input stream.

See Also:
Constant Field Values

READ_AHEAD

public static final int READ_AHEAD
Size to be used in marking an input stream.

See Also:
Constant Field Values
Constructor Detail

Formatter

public Formatter()
Method Detail

createPvFormat

public static java.lang.String createPvFormat(HttpConstant param,
                                              HttpConstant value)
Overloaded helper method for creating a HTTP proper response for a param value pair.

Parameters:
param - The HTTP parameter name
value - The Http parameter value
Returns:

createPvFormat

public static java.lang.String createPvFormat(HttpConstant param,
                                              int value)
Overloaded helper method for creating a HTTP proper response for a param value pair.

Parameters:
param - The HTTP parameter name
value - The Http parameter value
Returns:

createStatusLine

public static java.lang.String createStatusLine(HttpConstant statusId,
                                                java.lang.String msg)
Helper method for creating a properly formatted status line for the response.

Parameters:
statusId - The ID of the status e.g. 408 for request time out
msg - A short description of the status
Returns:

printToOutLn

public static void printToOutLn(java.lang.String msg)
Helper method that prints to stdout. Used to maintain a consistent look.

Parameters:
msg - The msg to print

printToErrLn

public static void printToErrLn(java.lang.Class caller,
                                java.lang.String methodName,
                                java.lang.String msg,
                                java.lang.String data)
Helper method that prints to the stderr details about a failure. To be used to describe what the program was trying to accomplish when a failure occured.

Parameters:
caller - The class that produced the error
methodName - The method name of the class where the error originated
msg - A shortdescription of the error
data - The offending data if any


This code is free for use both commercially and non-commercially as stated in the project's license