All Packages Class Hierarchy This Package Previous Next Index
Class com.sgi.sysadm.util.SysUtil
java.lang.Object
|
+----com.sgi.sysadm.util.SysUtil
- public class SysUtil
- extends Object
System utility functions.
-
createObject(String, Class, Class[], Object[])
- A static method to load a class and instantiate an object.
-
forName(String)
- Works around a bug in the code that loads classes for applets in
Java 1.2 (Java bug 4191520).
-
getSystemProperty(String)
- getSystemProperty is a wrapper for
System.getProperty that does not cause a torrent of
exceptions when called from an untrusted Applet.
-
getSystemProperty(String, String)
- getSystemProperty is a wrapper for
System.getProperty that does not cause a torrent of
exceptions when called from an untrusted Applet.
-
getTime(String)
- Get the timer information for timerName.
-
hostsEqual(String, String)
- Compares the IP addresses of the 2 hosts to see if they are the
same.
-
loadFont(String)
- Returns a font that matches the description given.
-
loadFont(String, int, int)
- Returns a font that matches the description given.
-
pixelsFromPoints(int)
- Convert points to pixels.
-
printTimer(String)
- Print timer information for timerName.
-
readLine(InputStream)
- Read one line of input from in.
-
resetAndStartTimer(String)
- Reset timer for timerName, and restart it.
-
resetTimer(String)
- Stop the timer named by timerName.
-
sizeFromWidth(int)
- Given a width in points, calculates the height based on the "golden"
UI ratio and returns a Dimension in pixels.
-
stackTraceToString(Throwable)
- Get the stack trace from th as a String.
-
startTimer(String)
- Start the timer named by timerName.
-
stopAndPrintTimer(String)
- Stop timer for timerName and print its value.
-
stopTimer(String)
- Stop the timer named by timerName.
startTimer
public static void startTimer(String timerName)
- Start the timer named by timerName.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to start.
stopTimer
public static void stopTimer(String timerName)
- Stop the timer named by timerName.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to stop.
resetTimer
public static void resetTimer(String timerName)
- Stop the timer named by timerName.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to stop.
printTimer
public static void printTimer(String timerName)
- Print timer information for timerName.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to print.
getTime
public static long getTime(String timerName)
- Get the timer information for timerName.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to print.
- Returns:
- The number of milliseconds that the timer ran.
resetAndStartTimer
public static void resetAndStartTimer(String timerName)
- Reset timer for timerName, and restart it.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to reset and start.
stopAndPrintTimer
public static void stopAndPrintTimer(String timerName)
- Stop timer for timerName and print its value.
Note: This is indended for internal Rhino development
and is subject to change.
- Parameters:
- timerName - Name of timer to stop and print.
getSystemProperty
public static String getSystemProperty(String key)
- getSystemProperty is a wrapper for
System.getProperty that does not cause a torrent of
exceptions when called from an untrusted Applet. This version
returns null if the property does not exist.
- Parameters:
- key - Key of property to get.
- Returns:
- value of property, or null if no such property exists.
- See Also:
- getProperty
getSystemProperty
public static String getSystemProperty(String key,
String defValue)
- getSystemProperty is a wrapper for
System.getProperty that does not cause a torrent of
exceptions when called from an untrusted Applet. This version
returns defValue if the property does not exist.
- Parameters:
- key - Key of property to get.
- defValue - Default value to return if property does not
exist.
- Returns:
- value of property, or defValue if no such
property exists.
- See Also:
- getProperty
readLine
public static String readLine(InputStream in) throws IOException
- Read one line of input from in.
- Parameters:
- in - InputStream to read from
- Returns:
- String representing the line of input.
- Throws: IOException
- if an I/O problem occurs.
createObject
public static Object createObject(String className,
Class returnType,
Class paramTypes[],
Object params[]) throws ClassNotFoundException, SysUtil. ClassLoadException
- A static method to load a class and instantiate an object.
This method instantiates the class named by className,
passing the params to the constructor, and makes sure
that what it loads is of type returnType. If the
returnType does not match, or if an exception is
thrown during object load or instantiation, then a
ClassLoadException is thrown.
This method is a convenience method so that callers don't have
to handle the messy details of loading a class, instantiating
an object, and handling all the Exceptions that could be thrown.
- Parameters:
- className - The name of the class to load
- returnType - The type of the Object to return. If the
Class that is loaded does not match this
type, a ClassLoadException is thrown.
- paramTypes - The types of the arguments to be passed to
the constructor
- params - The arguments to be passed to the constructor
- Throws: ClassNotFoundException
- if Class.forName method fails
when passed className.
- Throws: SysUtil. ClassLoadException
- if there are any exceptions
thrown during load or instantiation of the Object.
stackTraceToString
public static String stackTraceToString(Throwable th)
- Get the stack trace from th as a String.
- Parameters:
- th - Throwable from which to get a stack trace.
- Returns:
- String containing stack trace.
hostsEqual
public static boolean hostsEqual(String hostname1,
String hostname2)
- Compares the IP addresses of the 2 hosts to see if they are the
same. hostsEqual attempts to resolve both host names
and compare the resulting IP Addresses. If a SecurityException
occurs because we're running in an untrusted Applet,
hostsEqual falls back to doing a string compare.
If either hostname cannot be resolved for non-security reasons,
false is returned, even if the hostnames are the same.
Warning: This call can block for a long time (many
seconds) while the names are resolved. Don't call this from a
thread that can't block.
- Parameters:
- hostname1 - A Hostname.
- hostname2 - Another Hostname.
- Returns:
- true if IP addresses of the hostnames
exist and are the same. Returns false
otherwise.
pixelsFromPoints
public static int pixelsFromPoints(int points)
- Convert points to pixels. Experimentation has revealed that
there is no deterministic relationship between the screen
resolution returned by java.awt.Toolkit and and the number of
pixels in a point, even though a point is supposed to be 1/72
of an inch. So we determine our scale factor by picking a font
and dividing its pixel height by its point size.
- Parameters:
- points - points to convert to pixels.
- Returns:
- points converted to pixels.
sizeFromWidth
public static Dimension sizeFromWidth(int widthInPoints)
- Given a width in points, calculates the height based on the "golden"
UI ratio and returns a Dimension in pixels. The golden ratio
is 8.5:11.
- Parameters:
- widthInPoints - The width of an interface, in points.
- Returns:
- A Dimension in pixels where height has been calculated from
widthInPoints using the "golden" UI ratio.
forName
public static Class forName(String className) throws ClassNotFoundException
- Works around a bug in the code that loads classes for applets in
Java 1.2 (Java bug 4191520). Sometimes instead of throwing a
ClassNotFoundException, the class loader incorrectly throws a
ClassFormatError instead. This method catches the
ClassFormatError and then tries to determine if the app is
running as an applet by looking at the stack trace. If it's
determined that it was in an applet, then a warning will be
printed to the console and a ClassNotFoundException will be
thrown. Otherwise it's probably a real ClassFormatException,
and the method re-throws the original exception.
loadFont
public static Font loadFont(String name,
int style,
int size)
- Returns a font that matches the description given. All fonts
loaded via this method are cached, and subsequent requests for
a font are returned from the cache.
- Parameters:
- name - The name of the Font
- style - The style of the font (e.g. Font.BOLD)
- size - The size of the font
- Returns:
- A font matching the desctription.
loadFont
public static Font loadFont(String description)
- Returns a font that matches the description given. All fonts
loaded via this method are cached, and subsequent requests for
a font are returned from the cache.
- Parameters:
- description - A desciption of a font in the form
<name>-<style>-<size> (The same format taken
by Font.decode())
- Returns:
- A font matching the desctription.
All Packages Class Hierarchy This Package Previous Next Index