Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • classLoaders

        private static final java.util.Set<java.lang.ClassLoader> classLoaders
        set of class loaders to take resources from
    • 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, or null 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 or null if no resource with this name is found