Package io.micronaut.core.io
Class ResourceResolver
java.lang.Object
io.micronaut.core.io.ResourceResolver
Resolves resources from a set of
ResourceLoader
instances.- Since:
- 1.0
- Author:
- James Kleeh, graemerocher
-
Constructor Summary
ConstructorDescriptionDefault constructor.ResourceResolver
(@NonNull ResourceLoader[] resourceLoaders) ResourceResolver
(@NonNull List<ResourceLoader> resourceLoaders) -
Method Summary
Modifier and TypeMethodDescription<T extends ResourceLoader>
@NonNull Optional<T>Searches resource loaders for one that matches or is a subclass of the specified type.getLoaderForBasePath
(@NonNull String basePath) Searches resource loaders for one that supports the given path.getResource
(@NonNull String path) Searches resource loaders for one that supports the given path.Searches resource loaders for one that supports the given path.getResources
(@NonNull String path) Searches resource loaders for one that supports the given path.getSupportingLoader
(@NonNull String prefix) Searches resource loaders for one that supports the given prefix.
-
Constructor Details
-
ResourceResolver
- Parameters:
resourceLoaders
- The resource loaders
-
ResourceResolver
- 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
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
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
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
-