Class ResourceResolver

java.lang.Object
io.micronaut.core.io.ResourceResolver

public class ResourceResolver extends Object
Resolves resources from a set of ResourceLoader instances.
Since:
1.0
Author:
James Kleeh, graemerocher
  • Constructor Details

    • ResourceResolver

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

      public ResourceResolver(List<ResourceLoader> resourceLoaders)
      Parameters:
      resourceLoaders - The resource loaders
    • ResourceResolver

      public ResourceResolver()
      Default constructor.
  • Method Details

    • getLoader

      public <T extends ResourceLoader> Optional<T> getLoader(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

      public Optional<ResourceLoader> getSupportingLoader(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

      public Optional<ResourceLoader> getLoaderForBasePath(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

      public Optional<InputStream> getResourceAsStream(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

      public Optional<URL> getResource(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

      public Stream<URL> getResources(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