## php.java.bridge
Class Util

    java.lang.Object
      php.java.bridge.Util

    public class Util

extends java.lang.Object

Miscellaneous functions.

Author:
  jostb

Nested Class Summary
`static class` `Util.CgiEnvironment` A default CGI environment which contains a "SystemRoot" entry.
`static class` `Util.HeaderParser` A procedure class which can be used to capture the HTTP header strings.
`static class` `Util.Logger` A logger class.
`static class` `Util.Process` Starts a CGI process and returns the process handle.
`static class` `Util.ProcessWithErrorHandler` Starts a CGI process with an error handler attached and returns the process handle.

Field Summary
`static java.lang.String` `ASCII` ASCII encoding
`static int` `BACKLOG` Backlog for TCP and unix domain connections
`static int` `BUF_SIZE` The default buffer size
`static java.util.HashMap` `DEFAULT_CGI_ENVIRONMENT` The default CGI environment
`static java.lang.String[]` `DEFAULT_CGI_LOCATIONS` The default CGI locations: `"/usr/bin/php-cgi"`, `"/usr/bin/php"`, `"c:/php5/php-cgi.exe`
`static java.lang.String` `DEFAULT_EXTENSION_DIR` The default extension directory.
`static Util.HeaderParser` `DEFAULT_HEADER_PARSER` The default CGI header parser.
`static java.lang.String` `DEFAULT_LOG_FILE` The default log file.
`static int` `DEFAULT_LOG_LEVEL` The default log level, java.log_level from php.ini overrides.
`static java.lang.String` `EXTENSION_NAME` The name of the extension, usually "JavaBridge" or "MonoBridge"
`static int` `logLevel` The loglevel: 0: log off 1: log fatal 2: log messages/exceptions 3: log verbose 4: log debug 5: log method invocations
`static java.io.PrintStream` `logStream` The logStream, defaults to System.err
`static java.lang.String` `TCP_SOCKETNAME` The TCP socket name
`static java.lang.String` `THREAD_POOL_MAX_SIZE` The number of threads in the thread pool.
`static java.lang.String` `UTF8` UTF8 encoding

Constructor Summary
`Util()`

Method Summary
`static void` `appendArgs(java.lang.Object[] args, java.lang.Class[] params, java.lang.StringBuffer buf)` Append function arguments and their types to a StringBuffer
`static void` `appendObject(java.lang.Object obj, java.lang.StringBuffer buf)` Append an object to a StringBuffer
`static void` `appendParam(java.lang.Object obj, java.lang.StringBuffer buf)` Append a function parameter to a StringBuffer
`static void` `appendShortObject(java.lang.Object obj, java.lang.StringBuffer buf)` Append a parameter object to a StringBuffer
`static java.lang.String` `argsToString(java.lang.Object[] args, java.lang.Class[] params)` Return function arguments and their types as a String
`static java.lang.String` `checkCgiBinary(java.lang.StringBuffer buf)` Checks if the cgi binary buf-<os.arch>-<os.name>.sh or buf-<os.arch>-<os.name>.exe or buf-<os.arch>-<os.name> exists.
`static java.lang.String` `checkError(java.lang.String s)` Returns s if s starts with "PHP Fatal error:";
`static java.lang.Class` `getClass(java.lang.Object obj)` Return the class.
`static java.lang.String` `getClassName(java.lang.Object obj)` Return the class name
`static java.lang.ClassLoader` `getContextClassLoader()`
`static java.lang.String` `getHostAddress()` Returns the string "127.0.0.1".
`static Util.Logger` `getLogger()`
`static java.lang.String` `getShortClassName(java.lang.Object obj)` Return the short class name
`static java.lang.String[]` `hashToStringArray(java.util.Map h)` Create a string array from a hashtable.
`static void` `logDebug(java.lang.String msg)` Display a debug message
`static void` `logError(java.lang.String msg)` Display an error or an exception
`static void` `logFatal(java.lang.String msg)` Display a fatal error
`static void` `logMessage(java.lang.String msg)` Display a message
`static void` `parseBody(byte[] buf, java.io.InputStream natIn, java.io.OutputStream out, Util.HeaderParser parser)` Discards all header fields from a HTTP connection and write the body to the OutputStream
`static void` `println(int level, java.lang.String msg)` print a message on a given log level
`static void` `printStackTrace(java.lang.Throwable t)` Display a stack trace if logLevel >= 1
`static void` `setLogger(Util.Logger logger)`
`static byte[]` `toBytes(java.lang.String s)` Locale-independent getBytes(), uses ASCII encoding
`static void` `warn(java.lang.String msg)` Display a warning if logLevel >= 1

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### DEFAULT_CGI_LOCATIONS

    public static final java.lang.String[] DEFAULT_CGI_LOCATIONS

  The default CGI locations: `"/usr/bin/php-cgi"`, `"/usr/bin/php"`, `"c:/php5/php-cgi.exe`

### DEFAULT_HEADER_PARSER

    public static final Util.HeaderParser DEFAULT_HEADER_PARSER

  The default CGI header parser. The default implementation discards everything.

### DEFAULT_CGI_ENVIRONMENT

    public static final java.util.HashMap DEFAULT_CGI_ENVIRONMENT

  The default CGI environment

### ASCII

    public static final java.lang.String ASCII

  ASCII encoding

  See Also:
    Constant Field Values

### UTF8

    public static final java.lang.String UTF8

  UTF8 encoding

  See Also:
    Constant Field Values

### BUF_SIZE

    public static final int BUF_SIZE

  The default buffer size

  See Also:
    Constant Field Values

### TCP_SOCKETNAME

    public static java.lang.String TCP_SOCKETNAME

  The TCP socket name

### DEFAULT_EXTENSION_DIR

    public static java.lang.String DEFAULT_EXTENSION_DIR

  The default extension directory. Each php instance can pass its extension dir via a call to `setJarLibraryPath` or `setLibraryPath`.

  See Also:
    `JavaBridge.setJarLibraryPath(String, String)`, `JavaBridge.setLibraryPath(String, String)`

### EXTENSION_NAME

    public static java.lang.String EXTENSION_NAME

  The name of the extension, usually "JavaBridge" or "MonoBridge"

### THREAD_POOL_MAX_SIZE

    public static java.lang.String THREAD_POOL_MAX_SIZE

  The number of threads in the thread pool.

  See Also:
    `property `php.java.bridge.threads``

### DEFAULT_LOG_LEVEL

    public static int DEFAULT_LOG_LEVEL

  The default log level, java.log_level from php.ini overrides.

### BACKLOG

    public static int BACKLOG

  Backlog for TCP and unix domain connections

### DEFAULT_LOG_FILE

    public static java.lang.String DEFAULT_LOG_FILE

  The default log file.

### logStream

    public static java.io.PrintStream logStream

  The logStream, defaults to System.err

### logLevel

    public static int logLevel

  The loglevel:
  0: log off
  1: log fatal
  2: log messages/exceptions
  3: log verbose
  4: log debug
  5: log method invocations

Constructor Detail

### Util

    public Util()

Method Detail

### println

    public static void println(int level,
                               java.lang.String msg)

  print a message on a given log level

  Parameters:
    `level` - The log level
    `msg` - The message

### warn

    public static void warn(java.lang.String msg)

  Display a warning if logLevel >= 1

  Parameters:
    `msg` - The warn message

### printStackTrace

    public static void printStackTrace(java.lang.Throwable t)

  Display a stack trace if logLevel >= 1

  Parameters:
    `t` - The Throwable

### logDebug

    public static void logDebug(java.lang.String msg)

  Display a debug message

  Parameters:
    `msg` - The message

### logFatal

    public static void logFatal(java.lang.String msg)

  Display a fatal error

  Parameters:
    `msg` - The error

### logError

    public static void logError(java.lang.String msg)

  Display an error or an exception

  Parameters:
    `msg` - The error or the exception

### logMessage

    public static void logMessage(java.lang.String msg)

  Display a message

  Parameters:
    `msg` - The message

### getClassName

    public static java.lang.String getClassName(java.lang.Object obj)

  Return the class name

  Parameters:
    `obj` - The object
  Returns:
    The class name

### getShortClassName

    public static java.lang.String getShortClassName(java.lang.Object obj)

  Return the short class name

  Parameters:
    `obj` - The object
  Returns:
    The class name

### getClass

    public static java.lang.Class getClass(java.lang.Object obj)

  Return the class.

  Parameters:
    `obj` - The object
  Returns:
    The class

### appendObject

    public static void appendObject(java.lang.Object obj,
                                    java.lang.StringBuffer buf)

  Append an object to a StringBuffer

  Parameters:
    `obj` - The object
    `buf` - The StringBuffer

### appendShortObject

    public static void appendShortObject(java.lang.Object obj,
                                         java.lang.StringBuffer buf)

  Append a parameter object to a StringBuffer

  Parameters:
    `obj` - The object
    `buf` - The StringBuffer

### appendParam

    public static void appendParam(java.lang.Object obj,
                                   java.lang.StringBuffer buf)

  Append a function parameter to a StringBuffer

  Parameters:
    `obj` - The parameter object
    `buf` - The StringBuffer

### argsToString

    public static java.lang.String argsToString(java.lang.Object[] args,
                                                java.lang.Class[] params)

  Return function arguments and their types as a String

  Parameters:
    `args` - The args
    `params` - The associated types
  Returns:
    A new string

### appendArgs

    public static void appendArgs(java.lang.Object[] args,
                                  java.lang.Class[] params,
                                  java.lang.StringBuffer buf)

  Append function arguments and their types to a StringBuffer

  Parameters:
    `args` - The args
    `params` - The associated types
    `buf` - The StringBuffer

### toBytes

    public static byte[] toBytes(java.lang.String s)

  Locale-independent getBytes(), uses ASCII encoding

  Parameters:
    `s` - The String
  Returns:
    The ASCII encoded bytes

### hashToStringArray

    public static java.lang.String[] hashToStringArray(java.util.Map h)
                                                throws java.lang.NullPointerException

  Create a string array from a hashtable.

  Parameters:
    `h` - The hashtable
  Returns:
    The String
  Throws:
    `java.lang.NullPointerException`

### parseBody

    public static void parseBody(byte[] buf,
                                 java.io.InputStream natIn,
                                 java.io.OutputStream out,
                                 Util.HeaderParser parser)
                          throws java.io.UnsupportedEncodingException,
                                 java.io.IOException

  Discards all header fields from a HTTP connection and write the body to the OutputStream

  Parameters:
    `buf` - A buffer, for example new byte[BUF_SIZE]
    `natIn` - The InputStream
    `out` - The OutputStream
  Throws:
    `java.io.UnsupportedEncodingException`
    `java.io.IOException`

### setLogger

    public static void setLogger(Util.Logger logger)

  Parameters:
    `logger` - The logger to set.

### getLogger

    public static Util.Logger getLogger()

  Returns:
    Returns the logger.

### getHostAddress

    public static java.lang.String getHostAddress()

  Returns the string "127.0.0.1". If the system property "php.java.bridge.promiscuous" is "true", the real host address is returned.

  Returns:
    The host address as a string.

### checkCgiBinary

    public static java.lang.String checkCgiBinary(java.lang.StringBuffer buf)

  Checks if the cgi binary buf-<os.arch>-<os.name>.sh or buf-<os.arch>-<os.name>.exe or buf-<os.arch>-<os.name> exists.

  Parameters:
    `buf` - The base name, e.g.: /opt/tomcat/webapps/JavaBridge/WEB-INF/cgi/php-cgi
  Returns:
    The full name or null.

### checkError

    public static java.lang.String checkError(java.lang.String s)

  Returns s if s starts with "PHP Fatal error:";

  Parameters:
    `s` - The error string
  Returns:
    The fatal error or null

### getContextClassLoader

    public static java.lang.ClassLoader getContextClassLoader()

  Returns:
    The thread context class loader.