@Immutable public final class ClassLoaderHelper extends Object
ClassLoader utility methods.| Modifier and Type | Method and Description |
|---|---|
static ClassLoader |
getClassClassLoader(Class<?> aClass) |
static ClassLoader |
getContextClassLoader() |
static ClassLoader |
getDefaultClassLoader() |
static ClassLoader |
getParentClassLoader(ClassLoader aClassLoader) |
static URL |
getResource(ClassLoader aClassLoader,
String sPath)
Get the URL of the passed resource using the specified class loader only.
|
static InputStream |
getResourceAsStream(ClassLoader aClassLoader,
String sPath)
Get the input stream of the passed resource using the specified class
loader only.
|
static Enumeration<URL> |
getResources(ClassLoader aClassLoader,
String sPath)
Get all URLs of the passed resource using the specified class loader only.
|
static ClassLoader |
getSystemClassLoader() |
static void |
setContextClassLoader(ClassLoader aClassLoader) |
@Nonnull public static ClassLoader getSystemClassLoader()
@Nullable public static ClassLoader getContextClassLoader()
public static void setContextClassLoader(@Nonnull ClassLoader aClassLoader)
@Nullable public static ClassLoader getClassClassLoader(@Nonnull Class<?> aClass)
@Nullable public static ClassLoader getParentClassLoader(@Nonnull ClassLoader aClassLoader)
@Nonnull public static ClassLoader getDefaultClassLoader()
@Nullable public static URL getResource(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath)
classLoader.getResource (sPath).aClassLoader - The class loader to be used. May not be null.sPath - The path to be resolved. May neither be null nor empty.
Internally it is ensured that the provided path does NOT start with
a slash.null if the path could not be resolved using the
specified class loader.@Nonnull public static Enumeration<URL> getResources(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath) throws IOException
classLoader.getResources (sPath).aClassLoader - The class loader to be used. May not be null.sPath - The path to be resolved. May neither be null nor empty.
Internally it is ensured that the provided path does NOT start with
a slash.null if the path could not be resolved using the
specified class loader.IOException - In case an internal error occurs.@Nullable public static InputStream getResourceAsStream(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath)
classLoader.getResourceAsStream (sPath).aClassLoader - The class loader to be used. May not be null.sPath - The path to be resolved. May neither be null nor empty.
Internally it is ensured that the provided path does NOT start with
a slash.null if the path could not be resolved using the
specified class loader.Copyright © 2014–2019 Philip Helger. All rights reserved.