Class ResourceResolver
java.lang.Object
com.thecsdev.common.resource.ResourceResolver
A utility class for resolving and fetching resources from various
URIs.
This class provides methods to fetch resources asynchronously based on their URIs.
Different protocols can be handled by their corresponding ProtocolHandlers.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic final voidInternal method for bootstrapping theResourceResolverand registers default protocol handlers.static final @NotNull CompletableFuture<ResourceResponse> fetchAsync(@NotNull ResourceRequest request) Fetches a resource based on the providedResourceRequestasynchronously.static final @NotNull CompletableFuture<ResourceResponse> fetchAsync(@NotNull URI uri) Fetches a resource from the specifiedURIasynchronously.static final voidregisterProtocolHandler(@NotNull String scheme, @NotNull ProtocolHandler handler) Registers aProtocolHandlerfor a specific protocol scheme.
-
Method Details
-
registerProtocolHandler
public static final void registerProtocolHandler(@NotNull @NotNull String scheme, @NotNull @NotNull ProtocolHandler handler) throws NullPointerException Registers aProtocolHandlerfor a specific protocol scheme.- Parameters:
scheme- The protocol scheme (e.g., "http", "https", "file").handler- TheProtocolHandlerresponsible for handling the specified scheme.- Throws:
NullPointerException- If an argument isnull.
-
fetchAsync
@NotNull public static final @NotNull CompletableFuture<ResourceResponse> fetchAsync(@NotNull @NotNull URI uri) throws NullPointerException Fetches a resource from the specifiedURIasynchronously.- Parameters:
uri- TheURIof the resource to fetch.- Returns:
- A
CompletableFuturethat will complete with aResourceResponsecontaining the fetched resource data. - Throws:
NullPointerException- If the argument isnull.
-
fetchAsync
@NotNull public static final @NotNull CompletableFuture<ResourceResponse> fetchAsync(@NotNull @NotNull ResourceRequest request) throws NullPointerException Fetches a resource based on the providedResourceRequestasynchronously.- Parameters:
request- TheResourceRequestcontaining details about the resource to fetch.- Returns:
- A
CompletableFuturethat will complete with aResourceResponsecontaining the fetched resource data. - Throws:
NullPointerException- If the argument isnull.
-
bootstrap
@Internal public static final void bootstrap()Internal method for bootstrapping theResourceResolverand registers default protocol handlers.- API Note:
- Called automatically. Do not call this yourself.
-