|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.SystemUtil
public final class SystemUtil
System Utilities. These are helper functions for dealing with system functions.
Nested Class Summary | |
---|---|
static class |
SystemUtil.ValidCaller
A simple bean to hold the attributes of a valid caller for use by validateCaller method. |
Method Summary | |
---|---|
static void |
checkCalledFromUnitTest(java.lang.String className,
java.lang.String methodName)
Checks to make sure we are the specified class and method are invoked from unit tests. |
static int |
compare(boolean first,
boolean second)
Convenience function that calls compare(boolean,boolean,boolean)
with falseLessThanTrue == true . |
static int |
compare(boolean first,
boolean second,
boolean falseLessThanTrue)
Compares first and second and returns the
result. |
static int |
compare(java.lang.Comparable first,
java.lang.Comparable second)
Compares first to second and returns a
negative, zero or postive integer as first is
less than, equal to or greater than second ,
respectively. |
static int |
compare(java.lang.Comparable first,
java.lang.Comparable second,
boolean nullComparesGreaterThanNonNull)
Compares first to second and returns a
negative, zero or postive integer as first is
less than, equal to or greater than second ,
respectively. |
static int |
compare(java.lang.Object first,
java.lang.Object second,
java.util.Comparator comparator)
Compares first to second using the supplied
comparator and returns a negative, zero or postive integer
as first is less than, equal to or greater than
second , respectively. |
static int |
compare(java.lang.Object first,
java.lang.Object second,
java.util.Comparator comparator,
boolean nullComparesGreaterThanNonNull)
Compares first to second using the supplied
comparator and returns a negative, zero or postive integer
as first is less than, equal to or greater than
second , respectively. |
static void |
consumeException(java.lang.String reason,
java.lang.Throwable t)
Prevent a compiler warning when you don't want to do something in a catch block. |
static void |
consumeInterruptedException(java.lang.InterruptedException e)
Provide proper handling of InterruptedException from wait() and sleep() methods. |
static boolean |
equal(java.lang.Object one,
java.lang.Object two)
Check if two objects are equal in a null safe manner. |
static java.io.PrintWriter |
err()
Get a Writer version of System.err |
static void |
exit(int code)
Terminate the java process. |
static java.lang.String |
fixRelativePath(java.lang.String path)
Modify a relative file path to use custom config and directory locations |
static void |
flushOutput()
Flush system out and system error. |
static java.lang.String |
getArchitecture()
Return the OS architecture of this VM |
static java.lang.String |
getBootClassPath()
Returns the boot classpath of this VM. |
static java.lang.String |
getClassPath()
Return the class path of this VM. |
static java.lang.String |
getCompleteClassPath()
Returns the complete classpath used by this VM. |
static java.io.File |
getConfigDirectory()
Returns the config directory. |
static java.lang.String |
getConfigDirectoryString()
|
static java.net.URL |
getConfigURL()
Returns the config URL. |
static java.lang.String |
getCwd()
Get the current working directory as a String. |
static java.io.File |
getCwdFile()
Get the current working directory as a File |
static java.util.Map |
getenv()
For internal use only |
static java.lang.String |
getenv(java.lang.String envVar)
For internal use only |
static boolean |
getExitException()
Used for unit tests to check if an exception will be thrown when SystemUtil.exit() is calld. |
static java.lang.String |
getFileEncoding()
Return the default file encoding of this VM |
static java.net.InetAddress |
getHost()
Get the InetAddress for this machine. |
static java.lang.String |
getHostname()
Get the hostname of this machine. |
static java.io.File |
getInstallDirectory()
Returns the installation directory. |
static java.io.File |
getInternalDirectory()
Returns the internal directory. |
static java.lang.String |
getJavaVendor()
Return this VM's vendor |
static java.io.File |
getLocalTempDirectory()
Returns the temporary directory for the local server This directory can be used to store temporary files which do not need to be shared accross multiple processes |
static java.lang.String |
getOperatingSystem()
Return the OS name of this VM |
static java.lang.String |
getOperatingSystemType()
Return the OS type of this VM. |
static java.lang.String |
getPathSeparator()
Return the path separator of this VM. |
static char |
getPathSeparatorChar()
Return the path separator of this VM. |
static java.lang.String |
getPwd()
Find the current working directory. |
static java.lang.Throwable |
getRootCause(java.lang.Throwable t)
Returns the root cause that cause that causes this exception. |
static java.io.File |
getSharedTempDirectory()
Returns the temporary directory which can be shared accross multiple processes This directory can be used to store temporary files which require to be accessible by different nodes |
static java.io.File |
getSystemDirectory()
Returns the sytem directory. |
static java.lang.String |
getUserName()
Return the current user name |
static int |
hashCode(java.lang.Object object)
Convenience method that returns the hashCode() of
object . |
static int |
hostAsInt()
helper function to convert hostname into int for database storage |
static java.io.BufferedReader |
in()
Get a Reader version of System.in |
static boolean |
isAIX()
Determine if the system is a AIX based system. |
static boolean |
isDevelopment()
Are we in development, not production mode? This is a low level check needed for internal testing. |
static boolean |
isHP()
Determine if the system is a HP based system. |
static boolean |
isLinux()
Determine if the system is a Linux based system. |
static boolean |
isSunOS()
Determine if the system is a Sun based system. |
static boolean |
isWin32()
Determine if the system is a Windows based system. |
static boolean |
memoryCompare(byte[] a,
int aIndex,
byte[] b,
int bIndex,
int len)
Compares len bytes in array a starting with byte aIndex with len bytes in array b starting with byte bIndex. |
static java.io.PrintWriter |
out()
Get a Writer version of System.out |
static void |
setConfigDirectory(java.lang.String configDir)
Defines the location of the config directory. |
static void |
setErr(java.io.PrintWriter pw)
Set the output stream returned by SystemUtil.out(); |
static void |
setExitException(boolean value)
Used for unit tests to cause SystemUtil.exit() to thrown an exception rather than bring down the process. |
static void |
setJ2EEServerInUse()
|
static void |
setJ2EEServerInUse(boolean flag)
|
static void |
setLocalTempDirectory(java.lang.String tempDir)
Defines the location of the local temporary directory. |
static void |
setOut(java.io.PrintWriter pw)
Set the output stream returned by SystemUtil.out(); |
static void |
setSharedTempDirectory(java.lang.String tempDir)
Defines the location of the shared temporary directory. |
static void |
setSystemDirectory(java.lang.String systemDir)
Defines the location of the system directory. |
static void |
sleep(long sleepTime)
|
static java.lang.String |
stackTrace()
Get a string which represents the current call stack. |
static java.lang.String |
stackTrace(java.lang.Throwable t)
Get a string which represents the Throwable's call stack. |
static java.lang.String |
stackTraceCodePath()
Returns String stackTrace for current thread, reduced to focus on most relevant stack frames for analyzing application execution. |
static java.lang.String |
stackTraceCodePath(java.lang.String st)
Returns String stackTrace reduced to focus on most relevant stack frames for analyzing application execution, given a String stackTrace. |
static java.lang.String |
stackTraceCodePath(java.lang.Throwable t)
Returns String stackTrace for given Throwable, reduced to focus on most relevant stack frames for analyzing application execution. |
static boolean |
usingJ2EEServer()
|
static void |
validateCaller(SystemUtil.ValidCaller[] validCallers,
boolean fatalAssert)
Validates that a method is allowed to call another method. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void sleep(long sleepTime)
public static boolean equal(java.lang.Object one, java.lang.Object two)
one
- the first of two objects to comparetwo
- the second of two objects to compare
public static int hashCode(java.lang.Object object)
hashCode()
of
object
. The case of a null
object
is handled; zero is returned.
This method is complementary to the method equal(java.lang.Object, java.lang.Object)
which tests two
objects for equality in a null
safe manner.
object
- the object for which to return the hashcode
0
if object
is
null
public static int compare(java.lang.Comparable first, java.lang.Comparable second)
first
to second
and returns a
negative, zero or postive integer as first
is
less than, equal to or greater than second
,
respectively.
first
and second
may be null
.
A null
object is always considered to be less than
any non-null
object.
first
- the first Comparable
to compare,
may be null
second
- the first Comparable
to compare,
may be null
first
and second
public static int compare(java.lang.Comparable first, java.lang.Comparable second, boolean nullComparesGreaterThanNonNull)
first
to second
and returns a
negative, zero or postive integer as first
is
less than, equal to or greater than second
,
respectively.
first
and second
may be null
.
A null
object is always considered to be less than
any non-null
object.
first
- the first Comparable
to compare,
may be null
second
- the first Comparable
to compare,
may be null
first
and second
public static int compare(java.lang.Object first, java.lang.Object second, java.util.Comparator comparator)
first
to second
using the supplied
comparator
and returns a negative, zero or postive integer
as first
is less than, equal to or greater than
second
, respectively.
first
and second
may be null
.
A null
object is always considered to be less than
any non-null
object.
first
- the first Comparable
to compare,
may be null
second
- the first Comparable
to compare,
may be null
comparator
- the Comparator
to use when comparing, may
not be null
first
and second
public static int compare(java.lang.Object first, java.lang.Object second, java.util.Comparator comparator, boolean nullComparesGreaterThanNonNull)
first
to second
using the supplied
comparator
and returns a negative, zero or postive integer
as first
is less than, equal to or greater than
second
, respectively.
first
and second
may be null
.
A null
object is always considered to be less than
any non-null
object.
first
- the first Comparable
to compare,
may be null
second
- the first Comparable
to compare,
may be null
comparator
- the Comparator
to use when comparing
first
and second
public static int compare(boolean first, boolean second, boolean falseLessThanTrue)
first
and second
and returns the
result.
If falseLessThanTrue == true
then -1
is
returned if !first && second
and +1
is
returned if first && !second
and 0
when first == second
.
If falseLessThanTrue == false
the result is the opposite.
first
- the first of the two values to comparesecond
- the second of the two values to comparefalseLessThanTrue
- whether or not false
should be
considered less than true
public static int compare(boolean first, boolean second)
compare(boolean,boolean,boolean)
with falseLessThanTrue == true
.
public static void setExitException(boolean value)
public static boolean getExitException()
public static final void checkCalledFromUnitTest(java.lang.String className, java.lang.String methodName)
className
- the class namemethodName
- the method namepublic static void exit(int code)
code
- the exit code to pass to System.exit()public static boolean memoryCompare(byte[] a, int aIndex, byte[] b, int bIndex, int len)
a
- array of memory to compare with baIndex
- where to start compare in array ab
- array of memory to compare with abIndex
- where to start compare in array blen
- the number of bytes to compare.
public static java.lang.String getHostname()
ariba.rpc.server.Server#hostname()
public static java.net.InetAddress getHost()
public static int hostAsInt()
public static java.lang.String getPwd()
public static java.lang.String getCwd()
public static java.io.File getCwdFile()
public static java.lang.String getFileEncoding()
public static java.lang.String getClassPath()
public static java.lang.String getBootClassPath()
public static java.lang.String getCompleteClassPath()
public static java.lang.String getPathSeparator()
public static char getPathSeparatorChar()
public static java.lang.String getArchitecture()
public static java.lang.String getOperatingSystem()
public static java.lang.String getOperatingSystemType()
public static java.lang.String getJavaVendor()
public static java.lang.String getUserName()
public static final boolean isWin32()
public static final boolean isSunOS()
public static final boolean isHP()
public static final boolean isAIX()
public static final boolean isLinux()
public static java.io.BufferedReader in()
public static java.io.PrintWriter out()
public static java.io.PrintWriter err()
public static void setOut(java.io.PrintWriter pw)
public static void setErr(java.io.PrintWriter pw)
public static void flushOutput()
public static final void consumeException(java.lang.String reason, java.lang.Throwable t)
reason
- text reason for why you don't want to do anything.t
- throwable (usally exception) that was thrown.public static final void consumeInterruptedException(java.lang.InterruptedException e)
e
- exception that was thrown.public static java.lang.String stackTrace()
public static java.lang.String stackTraceCodePath()
public static java.lang.String stackTraceCodePath(java.lang.Throwable t)
public static java.lang.String stackTraceCodePath(java.lang.String st)
public static java.lang.String stackTrace(java.lang.Throwable t)
t
- the Throwable to get the stack trace from
public static java.lang.Throwable getRootCause(java.lang.Throwable t)
t
- the Throwable instance whose root cause is to be returned. If this is null, then null
is returned.
null
public static java.util.Map getenv()
public static java.lang.String getenv(java.lang.String envVar)
envVar
- the name of the requested environment variable. Must not be null.
public static void setJ2EEServerInUse()
public static void setJ2EEServerInUse(boolean flag)
public static boolean usingJ2EEServer()
public static final void setSystemDirectory(java.lang.String systemDir)
systemDir
- path of the system directory. Cannot be null.getSystemDirectory()
public static final void setConfigDirectory(java.lang.String configDir)
configDir
- path of the config directory. Cannot be null.getConfigDirectory()
public static final void setLocalTempDirectory(java.lang.String tempDir)
tempDir
- path of the temp directory. Cannot be null.getLocalTempDirectory()
public static final void setSharedTempDirectory(java.lang.String tempDir)
tempDir
- path of the temp directory. Cannot be null.getSharedTempDirectory()
public static java.io.File getSystemDirectory()
public static java.io.File getConfigDirectory()
public static java.lang.String getConfigDirectoryString()
public static java.net.URL getConfigURL()
public static java.io.File getLocalTempDirectory()
public static java.io.File getSharedTempDirectory()
public static java.lang.String fixRelativePath(java.lang.String path)
public static java.io.File getInstallDirectory()
public static boolean isDevelopment()
ServerInterface.isProduction()
public static java.io.File getInternalDirectory()
null
if the internal directory
does not exist.public static void validateCaller(SystemUtil.ValidCaller[] validCallers, boolean fatalAssert)
validCallers
- an array of valid callers. See the ValidCaller
constructor for details on what an entry looks like.
To improve this method's performance, valid callers that require
a search through the full stack should be at the end of the array.fatalAssert
- if true, an invalid caller causes a fatal assert, otherwise
a non-fatal assert.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |