Class ClassLoaderUtils
- java.lang.Object
-
- org.attoparser.ClassLoaderUtils
-
final class ClassLoaderUtils extends java.lang.ObjectUtility class for obtaining a correct classloader on which to operate from a specific class.
- Since:
- 2.0.5
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ClassLoaderclassClassLoaderprivate static java.lang.ClassLoadersystemClassLoaderprivate static booleansystemClassLoaderAccessibleFromClassClassLoader
-
Constructor Summary
Constructors Modifier Constructor Description privateClassLoaderUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.io.InputStreamfindResourceAsStream(java.lang.String resourceName)Try to obtain a resource by name, returning null if it could not be located.private static java.lang.ClassLoadergetClassClassLoader(java.lang.Class<?> clazz)private static java.lang.ClassLoadergetSystemClassLoader()private static java.lang.ClassLoadergetThreadContextClassLoader()private static booleanisKnownClassLoaderAccessibleFrom(java.lang.ClassLoader accessibleCL, java.lang.ClassLoader fromCL)private static booleanisKnownLeafClassLoader(java.lang.ClassLoader classLoader)(package private) static java.io.InputStreamloadResourceAsStream(java.lang.String resourceName)Obtain a resource by name, throwing an exception if it is not present.
-
-
-
Method Detail
-
loadResourceAsStream
static java.io.InputStream loadResourceAsStream(java.lang.String resourceName) throws java.io.IOExceptionObtain a resource by name, throwing an exception if it is not present.
First the context class loader will be used. If this class loader is not able to locate the resource, then the class class loader (ClassLoaderUtils.class.getClassLoader()) will be used if it is different from the thread context one. Last, the System class loader will be tried.
This method does never return null.
- Parameters:
resourceName- the name of the resource to be obtained.- Returns:
- an input stream on the resource (null never returned).
- Throws:
java.io.IOException- if the resource could not be located.
-
findResourceAsStream
static java.io.InputStream findResourceAsStream(java.lang.String resourceName)
Try to obtain a resource by name, returning null if it could not be located.
This method works very similarly to
loadResourceAsStream(String)but will just return null if the resource cannot be located by the sequence of class loaders being tried.- Parameters:
resourceName- the name of the resource to be obtained.- Returns:
- an input stream on the resource, or null if it could not be located.
-
getThreadContextClassLoader
private static java.lang.ClassLoader getThreadContextClassLoader()
-
getClassClassLoader
private static java.lang.ClassLoader getClassClassLoader(java.lang.Class<?> clazz)
-
getSystemClassLoader
private static java.lang.ClassLoader getSystemClassLoader()
-
isKnownClassLoaderAccessibleFrom
private static boolean isKnownClassLoaderAccessibleFrom(java.lang.ClassLoader accessibleCL, java.lang.ClassLoader fromCL)
-
isKnownLeafClassLoader
private static boolean isKnownLeafClassLoader(java.lang.ClassLoader classLoader)
-
-