java.lang.Object
com.github.mizosoft.methanol.MoreBodyPublishers
Factory for additional
HttpRequest.BodyPublisher
implementations.-
Method Summary
Modifier and TypeMethodDescriptionstatic MimeBodyPublisher
ofMediaType
(HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType) Adapts the givenBodyPublisher
into aMimeBodyPublisher
with the given media type.static HttpRequest.BodyPublisher
Returns aBodyPublisher
that encodes the given object into a request body using an installedencoder
.static HttpRequest.BodyPublisher
ofOutputStream
(ThrowingConsumer<? super OutputStream> writerTask, Executor executor) Returns aBodyPublisher
that reads what's written to theOutputStream
received by the given task.static HttpRequest.BodyPublisher
ofWritableByteChannel
(ThrowingConsumer<? super WritableByteChannel> writerTask, Executor executor) Returns aBodyPublisher
that reads what's written to theWritableByteChannel
received by the given task.
-
Method Details
-
ofOutputStream
public static HttpRequest.BodyPublisher ofOutputStream(ThrowingConsumer<? super OutputStream> writerTask, Executor executor) Returns aBodyPublisher
that reads what's written to theOutputStream
received by the given task. When the returned publisher receives a subscriber (i.e. when the HTTP client starts sending the request body), the given task is executed by the given executor to write the body's content. The latter is asynchronously channeled to the HTTP client. -
ofWritableByteChannel
public static HttpRequest.BodyPublisher ofWritableByteChannel(ThrowingConsumer<? super WritableByteChannel> writerTask, Executor executor) Returns aBodyPublisher
that reads what's written to theWritableByteChannel
received by the given task. When the returned publisher receives a subscriber (i.e. when the HTTP client starts sending the request body), the given task is executed by the given executor to write the body's content. The latter is asynchronously channeled to the HTTP client. -
ofMediaType
public static MimeBodyPublisher ofMediaType(HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType) Adapts the givenBodyPublisher
into aMimeBodyPublisher
with the given media type. -
ofObject
Returns aBodyPublisher
that encodes the given object into a request body using an installedencoder
.- Throws:
UnsupportedOperationException
- if noBodyAdapter.Encoder
that supports the given object's runtime type or the given media type is installed
-