Class ResourceResolver


  • public class ResourceResolver
    extends java.lang.Object
    Resolves resources from a set of ResourceLoader instances.
    Since:
    1.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T extends ResourceLoader>
      java.util.Optional<T>
      getLoader​(java.lang.Class<T> resolverType)
      Searches resource loaders for one that matches or is a subclass of the specified type.
      java.util.Optional<ResourceLoader> getLoaderForBasePath​(java.lang.String basePath)
      Searches resource loaders for one that supports the given path.
      java.util.Optional<java.net.URL> getResource​(java.lang.String path)
      Searches resource loaders for one that supports the given path.
      java.util.Optional<java.io.InputStream> getResourceAsStream​(java.lang.String path)
      Searches resource loaders for one that supports the given path.
      java.util.stream.Stream<java.net.URL> getResources​(java.lang.String path)
      Searches resource loaders for one that supports the given path.
      java.util.Optional<ResourceLoader> getSupportingLoader​(java.lang.String prefix)
      Searches resource loaders for one that supports the given prefix.
      • Methods inherited from class java.lang.Object

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

      • ResourceResolver

        public ResourceResolver​(@NonNull
                                ResourceLoader[] resourceLoaders)
        Parameters:
        resourceLoaders - The resource loaders
      • ResourceResolver

        public ResourceResolver​(@NonNull
                                java.util.List<ResourceLoader> resourceLoaders)
        Parameters:
        resourceLoaders - The resource loaders
      • ResourceResolver

        public ResourceResolver()
        Default constructor.
    • Method Detail

      • getLoader

        @NonNull
        public <T extends ResourceLoader> java.util.Optional<T> getLoader​(@NonNull
                                                                          java.lang.Class<T> resolverType)
        Searches resource loaders for one that matches or is a subclass of the specified type.
        Type Parameters:
        T - The type
        Parameters:
        resolverType - The type of resolver to retrieve
        Returns:
        An optional resource loader
      • getSupportingLoader

        @NonNull
        public java.util.Optional<ResourceLoader> getSupportingLoader​(@NonNull
                                                                      java.lang.String prefix)
        Searches resource loaders for one that supports the given prefix.
        Parameters:
        prefix - The prefix the loader should support. (classpath:, file:, etc)
        Returns:
        An optional resource loader
      • getLoaderForBasePath

        @NonNull
        public java.util.Optional<ResourceLoader> getLoaderForBasePath​(@NonNull
                                                                       java.lang.String basePath)
        Searches resource loaders for one that supports the given path. If found, create a new loader with the context of the base path.
        Parameters:
        basePath - The path to load resources from
        Returns:
        An optional resource loader
      • getResourceAsStream

        @NonNull
        public java.util.Optional<java.io.InputStream> getResourceAsStream​(@NonNull
                                                                           java.lang.String path)
        Searches resource loaders for one that supports the given path. If found, return the resource stream.
        Parameters:
        path - The path to the resource
        Returns:
        An optional input stream
      • getResource

        @NonNull
        public java.util.Optional<java.net.URL> getResource​(@NonNull
                                                            java.lang.String path)
        Searches resource loaders for one that supports the given path. If found, return the resource URL.
        Parameters:
        path - The path to the resource
        Returns:
        An optional URL
      • getResources

        @NonNull
        public java.util.stream.Stream<java.net.URL> getResources​(@NonNull
                                                                  java.lang.String path)
        Searches resource loaders for one that supports the given path. If found, return a stream of matching resources.
        Parameters:
        path - The path to the resource
        Returns:
        A stream of URLs