Class MoreBodyPublishers
java.lang.Object
com.github.mizosoft.methanol.MoreBodyPublishers
Static factories for additional
HttpRequest.BodyPublisher implementations.-
Method Summary
Modifier and TypeMethodDescriptionstatic MimeBodyPublisherofMediaType(HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType) Adapts the givenBodyPublisherinto aMimeBodyPublisherwith the given media type.static HttpRequest.BodyPublisherReturns aBodyPublisherthat encodes the given object into a request body using an installedencoder.static HttpRequest.BodyPublisherofOutputStream(ThrowingConsumer<? super OutputStream> writerTask, Executor executor) Returns aBodyPublisherthat reads what's written to theOutputStreamreceived by the given task.static HttpRequest.BodyPublisherofWritableByteChannel(ThrowingConsumer<? super WritableByteChannel> writerTask, Executor executor) Returns aBodyPublisherthat reads what's written to theWritableByteChannelreceived by the given task.
-
Method Details
-
ofOutputStream
public static HttpRequest.BodyPublisher ofOutputStream(ThrowingConsumer<? super OutputStream> writerTask, Executor executor) Returns aBodyPublisherthat reads what's written to theOutputStreamreceived 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 aBodyPublisherthat reads what's written to theWritableByteChannelreceived 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 givenBodyPublisherinto aMimeBodyPublisherwith the given media type. -
ofObject
Returns aBodyPublisherthat encodes the given object into a request body using an installedencoder.- Throws:
UnsupportedOperationException- if noBodyAdapter.Encoderthat supports the given object's runtime type or the given media type is installed
-