org.lateralnz.common.util
Class SystemUtils

java.lang.Object
  extended by org.lateralnz.common.util.SystemUtils

public class SystemUtils
extends java.lang.Object

various 'System' related functions


Method Summary
static void copyFile(java.lang.String f1, java.lang.String f2)
           
static java.lang.String[] exec(java.lang.String[] cmd, java.lang.String[] env, java.io.File f, long waitPeriod)
          execute a given command.
static java.lang.String getArgument(java.lang.String[] args, int idx, java.lang.String defaultValue)
          taking an array of arguments (usually in the main() method) return the value at a particular index -- or if it is null/empty, return a default value
static void getFileList(java.util.List filelist, java.lang.String directory, java.lang.String includesRegex, java.lang.String excludesRegex, boolean recursive)
          loads the specified list with File objects (recursing through directories if required)
static java.lang.String[] getFileList(java.lang.String directory, java.lang.String regex)
          get a list of files matching a regex
static byte[] getLocalhostIP()
          hopefully this will return the 'real' IP address even if the hosts file is configured incorrectly (as I discovered on my test machine...
static java.lang.reflect.Method getSetterMethod(java.lang.Class c, java.lang.String property, java.lang.Class[] paramTypes)
          get the "set" method for a property given a class and paramTypes array
static java.lang.Object invoke(java.lang.Object obj, java.lang.String method, java.lang.Object[] args)
          invoke a method on an object
static void invokeMain(java.lang.Class c, java.lang.String[] args)
          invoke the main method of a class
static void sleep(long time)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyFile

public static final void copyFile(java.lang.String f1,
                                  java.lang.String f2)
                           throws java.io.IOException
Throws:
java.io.IOException

exec

public static final java.lang.String[] exec(java.lang.String[] cmd,
                                            java.lang.String[] env,
                                            java.io.File f,
                                            long waitPeriod)
                                     throws java.io.IOException,
                                            java.lang.InterruptedException
execute a given command. This essentially wraps the command with a monitor so we can kill it after a certain period of time. At the moment this is useful for Jikes, since it seems to hang after certain errors, with no meaningful syserr output

Parameters:
cmd - the command array
env - the environment array
f - the file to use during the exec (@see java.lang.Runtime#getRuntime)
waitPeriod - the length of time to wait until we assume something has gone wrong and kill the process
Throws:
java.io.IOException
java.lang.InterruptedException

getArgument

public static final java.lang.String getArgument(java.lang.String[] args,
                                                 int idx,
                                                 java.lang.String defaultValue)
taking an array of arguments (usually in the main() method) return the value at a particular index -- or if it is null/empty, return a default value


getFileList

public static final java.lang.String[] getFileList(java.lang.String directory,
                                                   java.lang.String regex)
get a list of files matching a regex


getFileList

public static final void getFileList(java.util.List filelist,
                                     java.lang.String directory,
                                     java.lang.String includesRegex,
                                     java.lang.String excludesRegex,
                                     boolean recursive)
loads the specified list with File objects (recursing through directories if required)


getLocalhostIP

public static final byte[] getLocalhostIP()
hopefully this will return the 'real' IP address even if the hosts file is configured incorrectly (as I discovered on my test machine... JRB). However, If it really can't figure out the address it will return the loopback address.


getSetterMethod

public static final java.lang.reflect.Method getSetterMethod(java.lang.Class c,
                                                             java.lang.String property,
                                                             java.lang.Class[] paramTypes)
                                                      throws java.lang.NoSuchMethodException
get the "set" method for a property given a class and paramTypes array

Throws:
java.lang.NoSuchMethodException

invoke

public static final java.lang.Object invoke(java.lang.Object obj,
                                            java.lang.String method,
                                            java.lang.Object[] args)
                                     throws java.lang.IllegalAccessException,
                                            java.lang.reflect.InvocationTargetException,
                                            java.lang.NoSuchMethodException
invoke a method on an object

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

invokeMain

public static final void invokeMain(java.lang.Class c,
                                    java.lang.String[] args)
                             throws java.lang.IllegalAccessException,
                                    java.lang.reflect.InvocationTargetException,
                                    java.lang.NoSuchMethodException
invoke the main method of a class

Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException

sleep

public static final void sleep(long time)