Class ClassLoaderUtils
Utility class for obtaining a correct classloader on which to operate from a specific class.
- Since:
- 2.0.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ClassLoader
private static final ClassLoader
private static final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static InputStream
findResourceAsStream
(String resourceName) Try to obtain a resource by name, returning null if it could not be located.private static ClassLoader
getClassClassLoader
(Class<?> clazz) private static ClassLoader
private static ClassLoader
private static boolean
isKnownClassLoaderAccessibleFrom
(ClassLoader accessibleCL, ClassLoader fromCL) private static boolean
isKnownLeafClassLoader
(ClassLoader classLoader) (package private) static InputStream
loadResourceAsStream
(String resourceName) Obtain a resource by name, throwing an exception if it is not present.
-
Field Details
-
classClassLoader
-
systemClassLoader
-
systemClassLoaderAccessibleFromClassClassLoader
private static final boolean systemClassLoaderAccessibleFromClassClassLoader
-
-
Constructor Details
-
ClassLoaderUtils
private ClassLoaderUtils()
-
-
Method Details
-
loadResourceAsStream
Obtain 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:
IOException
- if the resource could not be located.
-
findResourceAsStream
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
-
getClassClassLoader
-
getSystemClassLoader
-
isKnownClassLoaderAccessibleFrom
private static boolean isKnownClassLoaderAccessibleFrom(ClassLoader accessibleCL, ClassLoader fromCL) -
isKnownLeafClassLoader
-