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(@NonNull @NonNull ResourceLoader[] resourceLoaders)
      Parameters:
      resourceLoaders - The resource loaders
    • ResourceResolver

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

      public ResourceResolver()
      Default constructor.
  • Method Details

    • getLoader

      @NonNull public <T extends ResourceLoader> @NonNull Optional<T> getLoader(@NonNull @NonNull 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 @NonNull Optional<ResourceLoader> getSupportingLoader(@NonNull @NonNull 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 @NonNull Optional<ResourceLoader> getLoaderForBasePath(@NonNull @NonNull 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 @NonNull Optional<InputStream> getResourceAsStream(@NonNull @NonNull 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 @NonNull Optional<URL> getResource(@NonNull @NonNull 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 @NonNull Stream<URL> getResources(@NonNull @NonNull 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