Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## php.java.bridge
Class Util

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

    public final class Util

extends java.lang.Object

Miscellaneous functions.

Author:
  jostb

Nested Class Summary
`static class` | `Util.HeaderParser` A procedure class which can be used to capture the HTTP header strings.
`static class` | `Util.Logger` A bridge which uses log4j or the default logger.
`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.Map` | `COMMON_ENVIRONMENT` A map containing common environment values for JDK <= 1.4: "PATH", "LD_LIBRARY_PATH", "LD_ASSUME_KERNEL", "USER", "TMP", "TEMP", "HOME", "HOMEPATH", "LANG", "TZ", "OS" They can be set with e.g.: `java -DPATH="$PATH" -DHOME="$HOME" -jar JavaBridge.jar` or `java -DPATH="%PATH%" -jar JavaBridge.jar`.
`static java.lang.String[]` | `DEFAULT_CGI_LOCATIONS` The default CGI locations: `"/usr/bin/php-cgi"`, `"c:/php/php-cgi.exe`
`static java.lang.String` | `DEFAULT_ENCODING` DEFAULT encoding for PHP 6 and above.
`static java.lang.String[]` | `DEFAULT_EXT_DIRS` The default extension directories.
`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 boolean` | `IS_MONO` Only for internal use
`static boolean` | `JAVABRIDGE_PROMISCUOUS` Set to true, if the Java VM has been started with -Dphp.java.bridge.promiscuous=true;
`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.lang.String` | `osArch` Only for internal use
`static java.lang.String` | `osName` Only for internal use
`static java.lang.String` | `TCP_SOCKETNAME` The TCP socket name.
`static java.lang.String` | `THREAD_POOL_MAX_SIZE` The max.
`static java.lang.String` | `UTF8` UTF8 encoding
`static java.lang.String` | `VERSION` Only for internal use

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 ILogger` | `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` | `setDefaultFileLogger()` Set the default logger.
`static void` | `setLogger(ILogger logger)` Set a new logger.
`static java.lang.String` | `stringValueOf(java.lang.Object object)` This procedure should be used whenever `object` may be a dynamic proxy: `String.valueOf(object) returns null, if object is a proxy and returns null.`
`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"`, `"c:/php/php-cgi.exe`

### DEFAULT_HEADER_PARSER

    public static final Util.HeaderParser DEFAULT_HEADER_PARSER

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

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

### DEFAULT_ENCODING

    public static final java.lang.String DEFAULT_ENCODING

  DEFAULT encoding for PHP 6 and above. Currently UTF-8, will be changed when most OS support and use UTF-16.

  See Also:
    Constant Field Values

### BUF_SIZE

    public static final int BUF_SIZE

  The default buffer size

  See Also:
    Constant Field Values

### DEFAULT_EXT_DIRS

    public static final java.lang.String[] DEFAULT_EXT_DIRS

  The default extension directories. If one of the directories "/usr/share/java/ext", "/usr/java/packages/lib/ext" contains java libraries, the bridge loads these libraries automatically. Useful if you have non-pure java libraries (=libraries which use the Java Native Interface to load native dll's or shared libraries).

### TCP_SOCKETNAME

    public static java.lang.String TCP_SOCKETNAME

  The TCP socket name. Default is 9267.

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

### 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 max. number of threads in the thread pool. Default is 20.

  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. Default is 3, if started via java -jar JavaBridge.jar or 2, if started as a sub-process of Apache/IIS.

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

### BACKLOG

    public static final int BACKLOG

  Backlog for TCP and unix domain connections.

  See Also:
    Constant Field Values

### JAVABRIDGE_PROMISCUOUS

    public static boolean JAVABRIDGE_PROMISCUOUS

  Set to true, if the Java VM has been started with -Dphp.java.bridge.promiscuous=true;

### DEFAULT_LOG_FILE

    public static java.lang.String DEFAULT_LOG_FILE

  The default log file. Default is stderr, if started as a sub-process of Apache/IIS or `EXTENSION_NAME`.log, if started via java -jar JavaBridge.jar.

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

### VERSION

    public static java.lang.String VERSION

  Only for internal use

### osArch

    public static java.lang.String osArch

  Only for internal use

### osName

    public static java.lang.String osName

  Only for internal use

### IS_MONO

    public static boolean IS_MONO

  Only for internal use

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

### COMMON_ENVIRONMENT

    public static final java.util.Map COMMON_ENVIRONMENT

  A map containing common environment values for JDK <= 1.4: "PATH", "LD_LIBRARY_PATH", "LD_ASSUME_KERNEL", "USER", "TMP", "TEMP", "HOME", "HOMEPATH", "LANG", "TZ", "OS" They can be set with e.g.: `java -DPATH="$PATH" -DHOME="$HOME" -jar JavaBridge.jar` or `java -DPATH="%PATH%" -jar JavaBridge.jar`.

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`

### setDefaultFileLogger

    public static void setDefaultFileLogger()

  Set the default logger.

### setLogger

    public static void setLogger(ILogger logger)

  Set a new logger. Example:
  `public class MyServlet extends PhpJavaServlet {
  public static final String LOG_HOST="192.168.5.99";
  public void init(ServletConfig config) throws ServletException {
  super.init(config);
  Util.setLogger(new php.java.bridge.ChainsawLogger() {public void configure(String host, int port) throws Exception {super.configure(LOG_HOST, port);}});
  }
  }

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

### getLogger

    public static ILogger 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.

### stringValueOf

    public static java.lang.String stringValueOf(java.lang.Object object)

  This procedure should be used whenever `object` may be a dynamic proxy: `String.valueOf(object) returns null, if object is a proxy and returns null.`

  Parameters:
    `object` - The object or dynamic proxy

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD