Package org.openstreetmap.josm.tools
Class ResourceProvider
- java.lang.Object
-
- org.openstreetmap.josm.tools.ResourceProvider
-
public final class ResourceProvider extends java.lang.Object
Unified provider that looks up for resource in various classloaders (josm, plugins, etc.).- Since:
- 15416
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Set<java.lang.ClassLoader>
classLoaders
set of class loaders to take resources from
-
Constructor Summary
Constructors Modifier Constructor Description private
ResourceProvider()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addAdditionalClassLoader(java.lang.ClassLoader additionalClassLoader)
Add an additional class loader to search image for.static boolean
addAdditionalClassLoaders(java.util.Collection<java.lang.ClassLoader> additionalClassLoaders)
Add a collection of additional class loaders to search image for.private static <T> T
getFirstNotNull(java.util.function.Function<java.lang.ClassLoader,T> function)
static java.net.URL
getResource(java.lang.String name)
Finds the resource with the given name.static java.io.InputStream
getResourceAsStream(java.lang.String name)
Finds a resource with a given name, with robustness to known JDK bugs.
-
-
-
Field Detail
-
classLoaders
private static final java.util.Set<java.lang.ClassLoader> classLoaders
set of class loaders to take resources from
-
-
Constructor Detail
-
ResourceProvider
private ResourceProvider()
-
-
Method Detail
-
addAdditionalClassLoader
public static boolean addAdditionalClassLoader(java.lang.ClassLoader additionalClassLoader)
Add an additional class loader to search image for.- Parameters:
additionalClassLoader
- class loader to add to the internal set- Returns:
true
if the set changed as a result of the call
-
addAdditionalClassLoaders
public static boolean addAdditionalClassLoaders(java.util.Collection<java.lang.ClassLoader> additionalClassLoaders)
Add a collection of additional class loaders to search image for.- Parameters:
additionalClassLoaders
- class loaders to add to the internal set- Returns:
true
if the set changed as a result of the call
-
getFirstNotNull
private static <T> T getFirstNotNull(java.util.function.Function<java.lang.ClassLoader,T> function)
-
getResource
public static java.net.URL getResource(java.lang.String name)
Finds the resource with the given name.- Parameters:
name
- The resource name- Returns:
- A
URL
object for reading the resource, ornull
if the resource could not be found or the invoker doesn't have adequate privileges to get the resource. - See Also:
ClassLoader.getResource(java.lang.String)
-
getResourceAsStream
public static java.io.InputStream getResourceAsStream(java.lang.String name)
Finds a resource with a given name, with robustness to known JDK bugs.- Parameters:
name
- name of the desired resource- Returns:
- A
InputStream
object ornull
if no resource with this name is found
-
-