public class ResourceLoader extends Object
ResourceLoader resourceLoader = ResourceLoader.builder()
.setBaseUrls(Arrays.asList(
new URL
Modifier and Type | Class and Description |
---|---|
static class |
ResourceLoader.Builder
Builder class for ResouceLoader.
|
Constructor and Description |
---|
ResourceLoader(Map<String,Function<URI,byte[]>> loaders,
Function<URI,byte[]> defaultLoader,
List<URL> baseUrls) |
Modifier and Type | Method and Description |
---|---|
static URL |
asURL(String u)
Helper function to convert a String url to a URL.
|
static List<URL> |
asURLs(Collection<String> baseUrls)
Helper function to convert a List of String urls to URLs.
|
static ResourceLoader.Builder |
builder()
Returns a ResourceLoader.Builder.
|
List<URI> |
getPossibleResourceUris(URI uri)
If the uri is aboslute, or if no baseUris are set, the only possible
uri is the provided one.
|
byte[] |
load(URI uri)
Loads the resource at uri, potentially prefixing relative URIs with baseUrls.
|
String |
toString() |
public ResourceLoader(Map<String,Function<URI,byte[]>> loaders, Function<URI,byte[]> defaultLoader, List<URL> baseUrls)
loaders
- Map of URI protocol/scheme (e.g. file, http, https, etc.) to
Function
that takes a URI
and returns a byte[] of the content at the URI.defaultLoader
- Default loader to use if no loader exists for the URI's scheme.baseUrls
- baseUrls prefixes that act like a relative URI search path.
When loading a uri, if that uri is relative, each baseUrl will
be prefixed to it and then attempted to be loaded.
Whichever baseUrl + uri successfully loads first will be returned.public byte[] load(URI uri) throws ResourceLoadingException
uri
- URI
ResourceLoadingException
public List<URI> getPossibleResourceUris(URI uri)
public static ResourceLoader.Builder builder()
public static List<URL> asURLs(Collection<String> baseUrls)
Copyright © 2025. All rights reserved.