Module methanol

Class MoreBodyPublishers

java.lang.Object
com.github.mizosoft.methanol.MoreBodyPublishers

public class MoreBodyPublishers extends Object
Factory for additional HttpRequest.BodyPublisher implementations.
  • Method Details

    • ofOutputStream

      public static HttpRequest.BodyPublisher ofOutputStream(ThrowingConsumer<? super OutputStream> writerTask, Executor executor)
      Returns a BodyPublisher that reads what's written to the OutputStream 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 a BodyPublisher that reads what's written to the WritableByteChannel 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 given BodyPublisher into a MimeBodyPublisher with the given media type.
    • ofObject

      public static HttpRequest.BodyPublisher ofObject(Object object, @Nullable MediaType mediaType)
      Returns a BodyPublisher that encodes the given object into a request body using an installed encoder.
      Throws:
      UnsupportedOperationException - if no BodyAdapter.Encoder that supports the given object's runtime type or the given media type is installed