Class ResourceMessage
java.lang.Object
com.thecsdev.common.resource.ResourceMessage
- Direct Known Subclasses:
ResourceRequest, ResourceResponse
public abstract sealed class ResourceMessage
extends Object
permits ResourceRequest, ResourceResponse
An abstract base class representing a message related to a resource identified
by a
This class serves as a common foundation for both
URI.This class serves as a common foundation for both
ResourceRequest and
ResourceResponse.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanfinal byte @NotNull []getData()Returns thebyte[]containing the raw byte data of thisResourceMessage.final @Nullable StringReturns the first metadata value associated with the specified metadata name.final @Nullable StringReturns the first metadata value associated with the specified metadata name.final @NotNull StringgetFirstOrThrow(@NotNull String metadataName) Returns the first metadata value associated with the specified metadata name, or throwsNoSuchElementExceptionif not found.Returns an unmodifiableMapcontaining metadata associated with the resource message.final @NotNull URIgetUri()Returns theURIassociated with this resource message.final booleanChecks if the specified metadata entry exists.inthashCode()
-
Constructor Details
-
ResourceMessage
protected ResourceMessage(@NotNull @NotNull URI resourceUri, @NotNull @NotNull Map<String, List<String>> metadata, byte @NotNull [] data) throws NullPointerException - Throws:
NullPointerException
-
-
Method Details
-
hashCode
-
equals
-
getUri
-
getMetadata
Returns an unmodifiableMapcontaining metadata associated with the resource message. This may include HTTP headers, system metadata, or other relevant information. Meanings vary based onURI.getScheme().The returned
Mapand all of itsListentries are all unmodifiable. -
has
Checks if the specified metadata entry exists.- Parameters:
metadataName- The name of the metadata entry.- Throws:
NullPointerException- If the argument isnull.
-
getFirst
@Nullable public final @Nullable String getFirst(@NotNull @NotNull String metadataName) throws NullPointerException Returns the first metadata value associated with the specified metadata name.- Parameters:
metadataName- The name of the metadata entry.- Throws:
NullPointerException- If aNotNullargument isnull.
-
getFirstOrThrow
@NotNull public final @NotNull String getFirstOrThrow(@NotNull @NotNull String metadataName) throws NullPointerException, NoSuchElementException Returns the first metadata value associated with the specified metadata name, or throwsNoSuchElementExceptionif not found.- Parameters:
metadataName- The name of the metadata entry.- Throws:
NullPointerException- If aNotNullargument isnull.NoSuchElementException- If no metadata entry is found for the specified name.
-
getFirst
@Contract("_, null -> _; _, !null -> !null") @Nullable public final @Nullable String getFirst(@NotNull @NotNull String metadataName, @Nullable @Nullable String defaultValue) throws NullPointerException Returns the first metadata value associated with the specified metadata name.- Parameters:
metadataName- The name of the metadata entry.defaultValue- The default value to return if the metadata entry is not found.- Throws:
NullPointerException- If aNotNullargument isnull.
-
getData
public final byte @NotNull [] getData()Returns thebyte[]containing the raw byte data of thisResourceMessage.
-