Package com.helger.commons.lang
Class ClassLoaderHelper
- java.lang.Object
-
- com.helger.commons.lang.ClassLoaderHelper
-
@Immutable public final class ClassLoaderHelper extends Object
ClassLoaderutility methods.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ClassLoadergetClassClassLoader(Class<?> aClass)static ClassLoadergetContextClassLoader()static ClassLoadergetDefaultClassLoader()static ClassLoadergetParentClassLoader(ClassLoader aClassLoader)static URLgetResource(ClassLoader aClassLoader, String sPath)Get the URL of the passed resource using the specified class loader only.static InputStreamgetResourceAsStream(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 ClassLoadergetSystemClassLoader()static voidsetContextClassLoader(ClassLoader aClassLoader)
-
-
-
Method Detail
-
getSystemClassLoader
@Nonnull public static ClassLoader getSystemClassLoader()
-
getContextClassLoader
@Nullable public static ClassLoader getContextClassLoader()
-
setContextClassLoader
public static void setContextClassLoader(@Nonnull ClassLoader aClassLoader)
-
getClassClassLoader
@Nullable public static ClassLoader getClassClassLoader(@Nonnull Class<?> aClass)
-
getParentClassLoader
@Nullable public static ClassLoader getParentClassLoader(@Nonnull ClassLoader aClassLoader)
-
getDefaultClassLoader
@Nonnull public static ClassLoader getDefaultClassLoader()
-
getResource
@Nullable public static URL getResource(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath)
Get the URL of the passed resource using the specified class loader only. This is a sanity wrapper aroundclassLoader.getResource (sPath).- Parameters:
aClassLoader- The class loader to be used. May not benull.sPath- The path to be resolved. May neither benullnor empty. Internally it is ensured that the provided path does NOT start with a slash.- Returns:
nullif the path could not be resolved using the specified class loader.
-
getResources
@Nonnull public static Enumeration<URL> getResources(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath) throws IOException
Get all URLs of the passed resource using the specified class loader only. This is a sanity wrapper aroundclassLoader.getResources (sPath).- Parameters:
aClassLoader- The class loader to be used. May not benull.sPath- The path to be resolved. May neither benullnor empty. Internally it is ensured that the provided path does NOT start with a slash.- Returns:
nullif the path could not be resolved using the specified class loader.- Throws:
IOException- In case an internal error occurs.
-
getResourceAsStream
@Nullable public static InputStream getResourceAsStream(@Nonnull ClassLoader aClassLoader, @Nonnull @Nonempty String sPath)
Get the input stream of the passed resource using the specified class loader only. This is a sanity wrapper aroundclassLoader.getResourceAsStream (sPath).- Parameters:
aClassLoader- The class loader to be used. May not benull.sPath- The path to be resolved. May neither benullnor empty. Internally it is ensured that the provided path does NOT start with a slash.- Returns:
nullif the path could not be resolved using the specified class loader.
-
-