Module methanol

Class MoreBodyPublishers


  • public class MoreBodyPublishers
    extends java.lang.Object
    Static factories for additional HttpRequest.BodyPublisher implementations.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static MimeBodyPublisher ofMediaType​(java.net.http.HttpRequest.BodyPublisher bodyPublisher, MediaType mediaType)
      Adapts the given BodyPublisher into a MimeBodyPublisher with the given media type.
      static java.net.http.HttpRequest.BodyPublisher ofObject​(java.lang.Object object, @Nullable MediaType mediaType)
      Returns a BodyPublisher that encodes the given object into a request body using an installed encoder.
      static java.net.http.HttpRequest.BodyPublisher ofOutputStream​(ThrowingConsumer<? super java.io.OutputStream> writerTask, java.util.concurrent.Executor executor)
      Returns a BodyPublisher that reads what's written to the OutputStream received by the given task.
      static java.net.http.HttpRequest.BodyPublisher ofWritableByteChannel​(ThrowingConsumer<? super java.nio.channels.WritableByteChannel> writerTask, java.util.concurrent.Executor executor)
      Returns a BodyPublisher that reads what's written to the WritableByteChannel received by the given task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • ofOutputStream

        public static java.net.http.HttpRequest.BodyPublisher ofOutputStream​(ThrowingConsumer<? super java.io.OutputStream> writerTask,
                                                                             java.util.concurrent.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 java.net.http.HttpRequest.BodyPublisher ofWritableByteChannel​(ThrowingConsumer<? super java.nio.channels.WritableByteChannel> writerTask,
                                                                                    java.util.concurrent.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​(java.net.http.HttpRequest.BodyPublisher bodyPublisher,
                                                    MediaType mediaType)
        Adapts the given BodyPublisher into a MimeBodyPublisher with the given media type.
      • ofObject

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