### 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 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

`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

## Method Summary

`static void`

`appendArgs(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(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`

`printStackTrace(java.lang.Throwable t)`
  Display a stack trace if logLevel >= 1

`static void`

`println(int level, java.lang.String msg)`
  print a message on a given log level

`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 Details

### ASCII

    public static final java.lang.String ASCII

> ASCII encoding

> Field Value:
>   ""

### BACKLOG

    public static int BACKLOG

> Backlog for TCP and unix domain connections

### BUF_SIZE

    public static final int BUF_SIZE

> The default buffer size

> Field Value:
>   8152

### DEFAULT_CGI_ENVIRONMENT

    public static final java.util.HashMap DEFAULT_CGI_ENVIRONMENT

> The default CGI environment

### 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_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)`

### DEFAULT_HEADER_PARSER

    public static final Util.HeaderParser DEFAULT_HEADER_PARSER

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

### DEFAULT_LOG_FILE

    public static java.lang.String DEFAULT_LOG_FILE

> The default log file.

### DEFAULT_LOG_LEVEL

    public static int DEFAULT_LOG_LEVEL

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

### EXTENSION_NAME

    public static java.lang.String EXTENSION_NAME

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

### TCP_SOCKETNAME

    public static java.lang.String TCP_SOCKETNAME

> The TCP socket name

### 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``

### UTF8

    public static final java.lang.String UTF8

> UTF8 encoding

> Field Value:
>   ""

### 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

### logStream

    public static java.io.PrintStream logStream

> The logStream, defaults to System.err

## Method Details

### appendArgs

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

> Append function arguments and their types to a StringBuffer

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

### 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

### 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

### 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

### argsToString

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

> Return function arguments and their types as a String

> Parameters:
>   `params` - The associated types

> Returns:
>   A new 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

### getClass

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

> Return the class.

> Parameters:
>   `obj` - The object

> Returns:
>   The class

### getClassName

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

> Return the class name

> Parameters:
>   `obj` - The object

> Returns:
>   The class name

### getContextClassLoader

    public static java.lang.ClassLoader getContextClassLoader()

> Returns:
>   The thread context class loader.

### 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.

### getLogger

    public static Util.Logger getLogger()

> Returns:
>   Returns the logger.

### getShortClassName

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

> Return the short class name

> Parameters:
>   `obj` - The object

> Returns:
>   The class name

### 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` -

### logDebug

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

> Display a debug message

> Parameters:
>   `msg` - The message

### logError

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

> Display an error or an exception

> Parameters:
>   `msg` - The error or the exception

### logFatal

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

> Display a fatal error

> Parameters:
>   `msg` - The error

### logMessage

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

> Display a message

> Parameters:
>   `msg` - The message

### 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` -

### printStackTrace

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

> Display a stack trace if logLevel >= 1

> Parameters:
>   `t` - The Throwable

### 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

### setLogger

    public static void setLogger(Util.Logger logger)

> Parameters:
>   `logger` - The logger to set.

### toBytes

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

> Locale-independent getBytes(), uses ASCII encoding

> Parameters:
>   `s` - The String

> Returns:
>   The ASCII encoded bytes

### warn

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

> Display a warning if logLevel >= 1

> Parameters:
>   `msg` - The warn message