- java.lang.Object
-
- com.github.mizosoft.methanol.adapter.AbstractBodyAdapter
-
- All Implemented Interfaces:
BodyAdapter
- Direct Known Subclasses:
BasicAdapter
public abstract class AbstractBodyAdapter extends java.lang.Object implements BodyAdapter
An abstractBodyAdapterthat implementsBodyAdapter.isCompatibleWith(MediaType)by allowing subclasses to specify a set ofMediaTypesthe adapter is compatible with.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractBodyAdapter.BaseDecoderThis interface abstracts the more-capableAbstractBodyAdapter.BaseDecoder.toObject(TypeRef, Hints)method and adds a default implementation forAbstractBodyAdapter.BaseDecoder.toObject(TypeRef, MediaType)that forwards to the former.static interfaceAbstractBodyAdapter.BaseEncoderThis interface abstracts the more-capableAbstractBodyAdapter.BaseEncoder.toBody(Object, TypeRef, Hints)method and adds a default implementation forAbstractBodyAdapter.BaseEncoder.toBody(Object, MediaType)that forwards to the former.-
Nested classes/interfaces inherited from interface com.github.mizosoft.methanol.BodyAdapter
BodyAdapter.Decoder, BodyAdapter.Encoder, BodyAdapter.Hints
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBodyAdapter(MediaType... compatibleMediaTypes)Creates anAbstractBodyAdaptercompatible with the given media types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.net.http.HttpRequest.BodyPublisherattachMediaType(java.net.http.HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType)Converts the given publisher into aMimeBodyPublisherthat has the given media type only if it is notnullorhas a wildcard, otherwise the given publisher is returned as-is.static java.nio.charset.CharsetcharsetOrDefault(@Nullable MediaType mediaType, java.nio.charset.Charset defaultCharset)Returns either the result ofMediaType.charsetOrDefault(Charset), or the given charset if the given media type isnull.static java.nio.charset.CharsetcharsetOrUtf8(@Nullable MediaType mediaType)Returns either the result ofMediaType.charsetOrDefault(Charset), orUTF-8if the given media type isnull.protected java.util.Set<MediaType>compatibleMediaTypes()Returns an immutable set containing the media types this adapter is compatible with.booleanisCompatibleWith(MediaType mediaType)Returnstrueif the format this adapter uses iscompatiblewith the given media type.protected voidrequireCompatibleOrNull(@Nullable MediaType mediaType)Requires that either this adapter iscompatiblewith the given media type, or the given media type isnull.protected voidrequireSupport(TypeRef<?> typeRef)Requires that this adaptersupportsthe given type.protected voidrequireSupport(TypeRef<?> typeRef, BodyAdapter.Hints hints)Requires that this adaptersupportsthe given type andis compatible withthe given hints' media type, if any.protected voidrequireSupport(java.lang.Class<?> type)Requires that this adaptersupportsthe given type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.mizosoft.methanol.BodyAdapter
supportsType
-
-
-
-
Constructor Detail
-
AbstractBodyAdapter
protected AbstractBodyAdapter(MediaType... compatibleMediaTypes)
Creates anAbstractBodyAdaptercompatible with the given media types.
-
-
Method Detail
-
isCompatibleWith
public final boolean isCompatibleWith(MediaType mediaType)
Description copied from interface:BodyAdapterReturnstrueif the format this adapter uses iscompatiblewith the given media type.- Specified by:
isCompatibleWithin interfaceBodyAdapter
-
compatibleMediaTypes
protected java.util.Set<MediaType> compatibleMediaTypes()
Returns an immutable set containing the media types this adapter is compatible with.
-
requireSupport
protected void requireSupport(TypeRef<?> typeRef)
Requires that this adaptersupportsthe given type.- Throws:
java.lang.UnsupportedOperationException- if this adapter doesn't support the given type.
-
requireSupport
protected void requireSupport(java.lang.Class<?> type)
Requires that this adaptersupportsthe given type.- Throws:
java.lang.UnsupportedOperationException- if this adapter doesn't support the given type.
-
requireSupport
protected void requireSupport(TypeRef<?> typeRef, BodyAdapter.Hints hints)
Requires that this adaptersupportsthe given type andis compatible withthe given hints' media type, if any.- Throws:
java.lang.UnsupportedOperationException- if this adapter doesn't support the given type or is not compatible with the given hints' media type.
-
requireCompatibleOrNull
protected void requireCompatibleOrNull(@Nullable MediaType mediaType)
Requires that either this adapter iscompatiblewith the given media type, or the given media type isnull.- Throws:
java.lang.UnsupportedOperationException- if this adapter is not compatible with the given media type.
-
charsetOrDefault
public static java.nio.charset.Charset charsetOrDefault(@Nullable MediaType mediaType, java.nio.charset.Charset defaultCharset)
Returns either the result ofMediaType.charsetOrDefault(Charset), or the given charset if the given media type isnull.
-
charsetOrUtf8
public static java.nio.charset.Charset charsetOrUtf8(@Nullable MediaType mediaType)
Returns either the result ofMediaType.charsetOrDefault(Charset), orUTF-8if the given media type isnull.
-
attachMediaType
public static java.net.http.HttpRequest.BodyPublisher attachMediaType(java.net.http.HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType)Converts the given publisher into aMimeBodyPublisherthat has the given media type only if it is notnullorhas a wildcard, otherwise the given publisher is returned as-is.
-
-