java.lang.Object
com.github.mizosoft.methanol.adapter.AbstractBodyAdapter
- All Implemented Interfaces:
BodyAdapter
- Direct Known Subclasses:
CharSequenceEncoder
,StringDecoder
Abstract
BodyAdapter
that implements BodyAdapter.isCompatibleWith(MediaType)
by
specifying a set of MediaTypes
the adapter is compatible with.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.mizosoft.methanol.BodyAdapter
BodyAdapter.Decoder, BodyAdapter.Encoder
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractBodyAdapter
(MediaType... compatibleMediaTypes) Creates anAbstractBodyAdapter
compatible with the given media types. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRequest.BodyPublisher
attachMediaType
(HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType) Converts the given publisher into aMimeBodyPublisher
only if the given media type is notnull
orhas a wildcard
, otherwise the given publisher is returned.static Charset
charsetOrDefault
(@Nullable MediaType mediaType, Charset defaultCharset) Returns either the result ofMediaType.charsetOrDefault(Charset)
ordefaultCharset
directly ifmediaType
is null.static Charset
charsetOrUtf8
(@Nullable MediaType mediaType) Returns either the result ofMediaType.charsetOrDefault(Charset)
orUTF-8
directly ifmediaType
is null.Returns an immutable set containing the media types this adapter is compatible with.final boolean
isCompatibleWith
(MediaType mediaType) Returnstrue
if the format this adapter uses iscompatible
with the given media type.protected void
requireCompatibleOrNull
(@Nullable MediaType mediaType) Requires that the given media type is eithernull
or is compatible with this adapter.protected void
requireSupport
(TypeRef<?> type) Requires that the given type is supported by this adapter.protected void
requireSupport
(Class<?> type) Requires that the given class is supported by this adapter.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 Details
-
AbstractBodyAdapter
Creates anAbstractBodyAdapter
compatible with the given media types.
-
-
Method Details
-
isCompatibleWith
Description copied from interface:BodyAdapter
Returnstrue
if the format this adapter uses iscompatible
with the given media type.- Specified by:
isCompatibleWith
in interfaceBodyAdapter
-
compatibleMediaTypes
Returns an immutable set containing the media types this adapter is compatible with. -
requireSupport
Requires that the given type is supported by this adapter.- Throws:
UnsupportedOperationException
- if this adapter doesn'tsupport
the given type.
-
requireSupport
Requires that the given class is supported by this adapter.- Throws:
UnsupportedOperationException
- if this adapter doesn'tsupport
the given raw type.
-
requireCompatibleOrNull
Requires that the given media type is eithernull
or is compatible with this adapter.- Throws:
UnsupportedOperationException
- if this adapter is notcompatible
the given type.
-
charsetOrDefault
Returns either the result ofMediaType.charsetOrDefault(Charset)
ordefaultCharset
directly ifmediaType
is null. -
charsetOrUtf8
Returns either the result ofMediaType.charsetOrDefault(Charset)
orUTF-8
directly ifmediaType
is null. -
attachMediaType
public static HttpRequest.BodyPublisher attachMediaType(HttpRequest.BodyPublisher publisher, @Nullable MediaType mediaType) Converts the given publisher into aMimeBodyPublisher
only if the given media type is notnull
orhas a wildcard
, otherwise the given publisher is returned.
-