Package com.helger.commons.lang
Class ClassLoaderHelper
java.lang.Object
com.helger.commons.lang.ClassLoaderHelper
ClassLoader utility methods.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClassLoadergetClassClassLoader(Class<?> aClass) static ClassLoaderstatic ClassLoaderstatic 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 ClassLoaderstatic voidsetContextClassLoader(ClassLoader aClassLoader)
-
Method Details
-
getSystemClassLoader
-
getContextClassLoader
-
setContextClassLoader
-
getClassClassLoader
-
getParentClassLoader
-
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.
-