public class SysUtil
extends java.lang.Object
For example it is strongly recommended to uset exit(int)
rather
than System.exit(int)
to terminate a JVM. It allows registered
listeners to be notified just before the exit happens.
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
AIX |
protected static java.lang.String |
DIGITAL_UNIX |
protected static java.lang.String |
FREE_BSD |
protected static java.lang.String |
HP_UX |
protected static java.lang.String |
IRIX |
protected static java.lang.String |
LINUX |
static java.lang.String |
OS_FAMILY_MACINTOSH
"macintosh"
|
static java.lang.String |
OS_FAMILY_UNIX
"unix"
|
static java.lang.String |
OS_FAMILY_UNKNOWN
"unknown"
|
static java.lang.String |
OS_FAMILY_WINDOWS
"windows"
|
protected static java.lang.String |
OS_PROPERTY_NAME |
protected static java.lang.String |
OSF1 |
protected static java.lang.String |
PF_OS_PROPERTY_NAME |
protected static java.lang.String |
SOLARIS |
protected static java.lang.String |
SUN_OS |
protected static java.lang.String[] |
UNIX_SYSTEMS |
Modifier | Constructor and Description |
---|---|
protected |
SysUtil()
Initialize the new instance with default values.
|
Modifier and Type | Method and Description |
---|---|
void |
addSystemExitListener(ISystemExitListener listener)
Add the given listener to an internal list so that it would be called right
before system exit gets executed via the
exit(int) method. |
protected static boolean |
checkIfWindows() |
boolean |
close(java.io.Closeable closeable)
Close the given closeable ignoring any exception and checking for null before closing.
|
static SysUtil |
current()
Returns the only instance this class supports (design pattern "Singleton")
|
protected boolean |
determineIfEclipse()
Returns true if the environment is based on eclipse.
|
protected static java.lang.String |
determineOsFamilyName() |
protected static java.lang.String |
determineOsFamilyName(java.lang.String operationSystemName) |
void |
exit(int rc)
Calling this method terminates the JVM.
|
void |
exit(int rc,
long sleepBeforeExit)
Calling this method terminates the JVM after the specified sleep time.
|
protected java.util.List<ISystemExitListener> |
getExitListeners() |
java.lang.String |
getOsFamily()
Returns the family name of the current operating system according to the
name specified in system property "os.name".
|
boolean |
isAppletEnvironment()
Returns true if the code is running as part of an applet in a browser
plugin JVM.
|
boolean |
isEclipse()
Returns true if the environment is based on eclipse.
|
boolean |
isWindows()
Returns true if the current operating-system is Windows.
|
protected void |
notifyExitListeners(int rc)
Inform all exit listeners that now the system will be exited.
|
void |
removeSystemExitListener(ISystemExitListener listener)
Removes the given listener from the internal list so that it would not
be notified anymore before system exit gets executed via the
exit(int)
method. |
protected void |
reset() |
protected void |
setExitListeners(java.util.List<ISystemExitListener> newValue) |
void |
sleep(long milliseconds)
Sets the current thread to sleep for the specified time in milliseconds
or until it gets interrupted.
|
public static final java.lang.String OS_FAMILY_UNKNOWN
public static final java.lang.String OS_FAMILY_WINDOWS
public static final java.lang.String OS_FAMILY_UNIX
public static final java.lang.String OS_FAMILY_MACINTOSH
protected static final java.lang.String OS_PROPERTY_NAME
protected static final java.lang.String PF_OS_PROPERTY_NAME
protected static final java.lang.String SOLARIS
protected static final java.lang.String SUN_OS
protected static final java.lang.String LINUX
protected static final java.lang.String AIX
protected static final java.lang.String HP_UX
protected static final java.lang.String FREE_BSD
protected static final java.lang.String DIGITAL_UNIX
protected static final java.lang.String OSF1
protected static final java.lang.String IRIX
protected static final java.lang.String[] UNIX_SYSTEMS
protected java.util.List<ISystemExitListener> getExitListeners()
protected void setExitListeners(java.util.List<ISystemExitListener> newValue)
public static SysUtil current()
protected static boolean checkIfWindows()
protected static java.lang.String determineOsFamilyName()
protected static java.lang.String determineOsFamilyName(java.lang.String operationSystemName)
public boolean isWindows()
public boolean isEclipse()
public boolean isAppletEnvironment()
public java.lang.String getOsFamily()
OS_FAMILY_UNKNOWN
,
OS_FAMILY_UNIX
,
OS_FAMILY_MACINTOSH
,
OS_FAMILY_WINDOWS
public void sleep(long milliseconds)
milliseconds
- The time to sleeppublic void exit(int rc)
rc
- The return code to the program that started the JVM.public void exit(int rc, long sleepBeforeExit)
rc
- The return code to the program that started the JVM.sleepBeforeExit
- The time to sleep (in milliseconds) before exiting.public void addSystemExitListener(ISystemExitListener listener)
exit(int)
method.
listener
- The listener to add. Will be ignored if null.public void removeSystemExitListener(ISystemExitListener listener)
exit(int)
method.
listener
- The listener to remove. Will be ignored if null.public boolean close(java.io.Closeable closeable)
protected void notifyExitListeners(int rc)
rc
- The return code for the exit.protected boolean determineIfEclipse()
protected void reset()