Enum ClassLoaderHelper
- All Implemented Interfaces:
Serializable
,Comparable<ClassLoaderHelper>
,java.lang.constant.Constable
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Method Summary
Modifier and TypeMethodDescriptionstatic URL
getResource
(String resource, boolean classesFirst, Class<?>... classes) If classesFirst is false, retrieves the resource via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.static URL
getResource
(String resource, Class<?>... classes) Retrieves the resource via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.static InputStream
getResourceAsStream
(String resource, boolean classesFirst, Class<?>... classes) If classesFirst is false, retrieves the resource as an input stream via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.static InputStream
getResourceAsStream
(String resource, Class<?>... classes) Retrieves the resource as an input stream via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.static Class<?>
If classesFirst is false, loads the class via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the caller class loader as the last resort.static Class<?>
Loads the class via the optionally specified classes in the order of their specification, and if not found, via the context class loader of the current thread, and if not found, from the caller class loader as the last resort.static ClassLoaderHelper
Returns the enum constant of this type with the specified name.static ClassLoaderHelper[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getResource
Retrieves the resource via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.- Parameters:
resource
- resource to be loadedclasses
- class loader providers- Returns:
- the resource loaded as an URL or null if not found.
-
getResource
If classesFirst is false, retrieves the resource via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.If classesFirst is true, retrieves the resource via the optionally specified classes in the order of their specification, and if not found, via the context class loader of the current thread, and if not found, from the class loader of
ClassLoaderHelper
as the last resort.- Parameters:
resource
- resource to be loadedclassesFirst
- true if the class loaders of the optionally specified classes take precedence over the context class loader of the current thread; false if the opposite is true.classes
- class loader providers- Returns:
- the resource loaded as an URL or null if not found.
-
loadClass
Loads the class via the optionally specified classes in the order of their specification, and if not found, via the context class loader of the current thread, and if not found, from the caller class loader as the last resort.- Parameters:
fqcn
- fully qualified class name of the target class to be loadedclasses
- class loader providers- Returns:
- the class loaded; never null
- Throws:
ClassNotFoundException
- if failed to load the class
-
loadClass
public static Class<?> loadClass(String fqcn, boolean classesFirst, Class<?>... classes) throws ClassNotFoundException If classesFirst is false, loads the class via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the caller class loader as the last resort.If classesFirst is true, loads the class via the optionally specified classes in the order of their specification, and if not found, via the context class loader of the current thread, and if not found, from the caller class loader as the last resort.
- Parameters:
fqcn
- fully qualified class name of the target class to be loadedclassesFirst
- true if the class loaders of the optionally specified classes take precedence over the context class loader of the current thread; false if the opposite is true.classes
- class loader providers- Returns:
- the class loaded; never null
- Throws:
ClassNotFoundException
- if failed to load the class
-
getResourceAsStream
Retrieves the resource as an input stream via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.- Parameters:
resource
- resource to be loadedclasses
- class loader providers- Returns:
- the resource loaded as an input stream or null if not found.
-
getResourceAsStream
public static InputStream getResourceAsStream(String resource, boolean classesFirst, Class<?>... classes) If classesFirst is false, retrieves the resource as an input stream via the context class loader of the current thread, and if not found, via the class loaders of the optionally specified classes in the order of their specification, and if not found, from the class loader ofClassLoaderHelper
as the last resort.If classesFirst is true, retrieves the resource as an input stream via the optionally specified classes in the order of their specification, and if not found, via the context class loader of the current thread, and if not found, from the class loader of
ClassLoaderHelper
as the last resort.- Parameters:
resource
- resource to be loadedclassesFirst
- true if the class loaders of the optionally specified classes take precedence over the context class loader of the current thread; false if the opposite is true.classes
- class loader providers- Returns:
- the resource loaded as an input stream or null if not found.
-