public final class ObjectUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
appendHex(StringBuffer buffer,
int value) |
static Properties |
argsToProps(String[] args)
Convenience method to parse an argument vector (typically from
the command line) and sets any arguments of the form "-Dy=x"
as values in a properties object.
|
static String |
bufToString(byte[] values,
int start,
int len) |
static Class<?> |
classForName(String name)
Returns the
Class object for the class or interface
with the given string name. |
static URL |
getResource(String name) |
static String |
readURL(String url) |
static char |
toAscii(byte value) |
static String |
toHex(byte value)
toHex converts a byte into a readable string. |
public static String readURL(String url) throws IOException
IOException
public static Class<?> classForName(String name) throws ClassNotFoundException, IllegalArgumentException
Class
object for the class or interface
with the given string name. This method is a replacement for
Class.forName(String name)
. Unlike
Class.forName(String name)
(which always uses the
caller's loader or one of its ancestors), classForName
uses a thread-specific loader that has no delegation relationship
with the caller's loader. It attempts the load the desired class
with the thread-specific context class loader and falls back to
Class.forName(String name)
only if the context class
loader cannot load the class.
Loading a class with a loader that is not necessarily an ancestor
of the caller's loader is a crucial thing in many scenarios. As an
example, assume that JacORB was loaded by the boot class loader,
and suppose that some code in JacORB contains a call
Class.forName(someUserClass)
. Such usage of
Class.forName
effectively forces the user to place
someUserClass
in the boot class path. If
classForName(someUserClass)
were used instead, the user
class would be loaded by the context class loader, which by default
is set to the system (CLASSPATH) classloader.
In this simple example above, the default setting of the context class loader allows classes in the boot classpath to reach classes in the system classpath. In other scenarios, the context class loader might be different from the system classloader. Middleware systems like servlet containers or EJB containers set the context class loader so that a given thread can reach user-provided classes that are not in the system classpath.
For maximum flexibility, classForName
should replace
Class.forName(String name)
in nearly all cases.
name
- the fully qualified name of a classIllegalArgumentException
- if name
is nullClassNotFoundException
- if the named class cannot be foundLinkageError
- if the linkage failsExceptionInInitializerError
- if the class initialization failspublic static String bufToString(byte[] values, int start, int len)
public static void appendHex(StringBuffer buffer, int value)
public static String toHex(byte value)
toHex
converts a byte into a readable string.value
- a byte
valueString
valuepublic static char toAscii(byte value)
public static Properties argsToProps(String[] args)
Copyright © 2017 JacORB. All rights reserved.