Package com.twelvemonkeys.lang
Class SystemUtil
java.lang.Object
com.twelvemonkeys.lang.SystemUtil
A utility class with some useful system-related functions.
NOTE: This class is not considered part of the public API and may be changed without notice
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/lang/SystemUtil.java#3 $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
This class marks an inputstream as containing XML, does nothing -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
private static Class
getClass
(String pClassName, boolean pInitialize, ClassLoader pLoader) private static InputStream
getFileAsStream
(String pName, boolean pGuessSuffix) Gets the named file as a stream from the current directory.private static InputStream
getResourceAsStream
(ClassLoader pClassLoader, String pName, boolean pGuessSuffix) Gets the named resource as a stream from the given Class' Classoader.static boolean
isClassAvailable
(String pClassName) Tests if a named class is generally available.static boolean
isClassAvailable
(String pClassName, Class pFromClass) Tests if a named class is available from another class.private static boolean
isClassAvailable
(String pClassName, ClassLoader pLoader) static boolean
isFieldAvailable
(String pClassName, String pFieldName) static boolean
isFieldAvailable
(String pClassName, String pFieldName, Class pFromClass) private static boolean
isFieldAvailable
(String pClassName, String pFieldName, ClassLoader pLoader) static boolean
isMethodAvailable
(String pClassName, String pMethodName) static boolean
isMethodAvailable
(String pClassName, String pMethodName, Class[] pParams) static boolean
isMethodAvailable
(String pClassName, String pMethodName, Class[] pParams, Class pFromClass) private static boolean
isMethodAvailable
(String pClassName, String pMethodName, Class[] pParams, ClassLoader pLoader) private static Properties
loadProperties
(InputStream pInput) Returns a Properties, loaded from the given inputstream.static Properties
loadProperties
(Class pClass) Utility method for loading a properties-file for a given class.static Properties
loadProperties
(Class pClass, String pName) Utility method for loading a named properties-file for a class.static Properties
loadProperties
(String pName) Utility method for loading a named properties-file.static void
-
Field Details
-
XML_PROPERTIES
".xml"
-
STD_PROPERTIES
".properties"
-
-
Constructor Details
-
SystemUtil
private SystemUtil()
-
-
Method Details
-
getResourceAsStream
private static InputStream getResourceAsStream(ClassLoader pClassLoader, String pName, boolean pGuessSuffix) Gets the named resource as a stream from the given Class' Classoader. If the pGuessSuffix parameter is true, the method will try to append typical properties file suffixes, such as ".properties" or ".xml".- Parameters:
pClassLoader
- the class loader to usepName
- name of the resourcepGuessSuffix
- guess suffix- Returns:
- an input stream reading from the resource
-
getFileAsStream
Gets the named file as a stream from the current directory. If the pGuessSuffix parameter is true, the method will try to append typical properties file suffixes, such as ".properties" or ".xml".- Parameters:
pName
- name of the resourcepGuessSuffix
- guess suffix- Returns:
- an input stream reading from the resource
-
loadProperties
Utility method for loading a named properties-file for a class.The properties-file is loaded through either:
- The given class' class loader (from classpath)
- Or, the system class loader (from classpath)
- Or, if it cannot be found in the classpath, an attempt to read from the current directory (or full path if given).
Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).
- Parameters:
pClass
- The class to load properties for. If this parameter isnull
, the method will work exactly asloadProperties(String)
pName
- The name of the properties-file. If this parameter isnull
, the method will work exactly asloadProperties(Class)
- Returns:
- A Properties mapping read from the given file or for the given class.
- Throws:
NullPointerException
- if bothpName
andpClass
paramters arenull
IOException
- if an error occurs during load.FileNotFoundException
- if no properties-file could be found.- See Also:
-
loadProperties
Utility method for loading a properties-file for a given class. The properties are searched for on the form "com/package/ClassName.properties" or "com/package/ClassName.xml".The properties-file is loaded through either:
- The given class' class loader (from classpath)
- Or, the system class loader (from classpath)
- Or, if it cannot be found in the classpath, an attempt to read from the current directory (or full path if given).
Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).
- Parameters:
pClass
- The class to load properties for- Returns:
- A Properties mapping for the given class.
- Throws:
NullPointerException
- if thepClass
paramters isnull
IOException
- if an error occurs during load.FileNotFoundException
- if no properties-file could be found.- See Also:
-
loadProperties
Utility method for loading a named properties-file.The properties-file is loaded through either:
- The system class loader (from classpath)
- Or, if it cannot be found in the classpath, an attempt to read from the current directory.
Both normal java.util.Properties and com.twelvemonkeys.util.XMLProperties are supported (XML-properties must have ".xml" as its file extension).
- Parameters:
pName
- The name of the properties-file.- Returns:
- A Properties mapping read from the given file.
- Throws:
NullPointerException
- if thepName
paramters isnull
IOException
- if an error occurs during load.FileNotFoundException
- if no properties-file could be found.- See Also:
-
loadProperties
Returns a Properties, loaded from the given inputstream. If the given inputstream is null, then an empty Properties object is returned.- Parameters:
pInput
- the inputstream to read from- Returns:
- a Properties object read from the given stream, or an empty Properties mapping, if the stream is null.
- Throws:
IOException
- if an error occurred when reading from the input stream.
-
clone
- Throws:
CloneNotSupportedException
-
main
- Throws:
CloneNotSupportedException
-
isClassAvailable
Tests if a named class is generally available. If a class is considered available, a call toClass.forName(pClassName)
will not result in an exception.- Parameters:
pClassName
- the class name to test- Returns:
true
if available
-
isClassAvailable
Tests if a named class is available from another class. If a class is considered available, a call toClass.forName(pClassName, true, pFromClass.getClassLoader())
will not result in an exception.- Parameters:
pClassName
- the class name to testpFromClass
- the class to test from- Returns:
true
if available
-
isClassAvailable
-
isFieldAvailable
-
isFieldAvailable
-
isFieldAvailable
-
isMethodAvailable
-
isMethodAvailable
-
isMethodAvailable
-
isMethodAvailable
private static boolean isMethodAvailable(String pClassName, String pMethodName, Class[] pParams, ClassLoader pLoader) -
getClass
private static Class getClass(String pClassName, boolean pInitialize, ClassLoader pLoader) throws ClassNotFoundException - Throws:
ClassNotFoundException
-