Module methanol

Class MoreBodyHandlers


  • public class MoreBodyHandlers
    extends java.lang.Object
    Static factories for additional HttpResponse.BodyHandler implementations.
    • Method Detail

      • fromAsyncSubscriber

        public static <T,​S extends java.util.concurrent.Flow.Subscriber<? super java.util.List<java.nio.ByteBuffer>>> java.net.http.HttpResponse.BodyHandler<T> fromAsyncSubscriber​(S downstream,
                                                                                                                                                                                          java.util.function.Function<? super S,​? extends java.util.concurrent.CompletionStage<T>> asyncFinisher)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.fromAsyncSubscriber(Subscriber, Function).
      • withReadTimeout

        public static <T> java.net.http.HttpResponse.BodyHandler<T> withReadTimeout​(java.net.http.HttpResponse.BodyHandler<T> delegate,
                                                                                    java.time.Duration timeout)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.withReadTimeout(BodySubscriber, Duration).
      • ofByteChannel

        public static java.net.http.HttpResponse.BodyHandler<java.nio.channels.ReadableByteChannel> ofByteChannel()
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofByteChannel(). The response is completed as soon as headers are received.
      • ofReader

        public static java.net.http.HttpResponse.BodyHandler<java.io.Reader> ofReader()
        Returns a BodyHandler that returns a subscriber obtained form MoreBodySubscribers.ofReader(Charset) using the charset specified by the Content-Type header, or UTF-8 if not present. The response is completed as soon as headers are received.
      • ofReader

        public static java.net.http.HttpResponse.BodyHandler<java.io.Reader> ofReader​(java.nio.charset.Charset charset)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofReader(Charset) using the given charset. The response is completed as soon as headers are received.
      • ofObject

        public static <T> java.net.http.HttpResponse.BodyHandler<T> ofObject​(java.lang.Class<T> type)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofObject(TypeRef, MediaType). The media type is parsed from the Content-Type response header if present.
        Throws:
        java.lang.UnsupportedOperationException - if no BodyAdapter.Decoder that supports the given type is installed
      • ofObject

        public static <T> java.net.http.HttpResponse.BodyHandler<T> ofObject​(TypeRef<T> typeRef)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofObject(TypeRef, MediaType). The media type is parsed from the Content-Type response header if present.
        Throws:
        java.lang.UnsupportedOperationException - if no BodyAdapter.Decoder that supports the given type is installed
      • ofDeferredObject

        public static <T> java.net.http.HttpResponse.BodyHandler<java.util.function.Supplier<T>> ofDeferredObject​(java.lang.Class<T> type)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofDeferredObject(TypeRef, MediaType). The media type is parsed from the Content-Type response header if present. The response is completed as soon as headers are received.
        Throws:
        java.lang.UnsupportedOperationException - if no BodyAdapter.Decoder that supports the given type is installed
      • ofDeferredObject

        public static <T> java.net.http.HttpResponse.BodyHandler<java.util.function.Supplier<T>> ofDeferredObject​(TypeRef<T> typeRef)
        Returns a BodyHandler that returns a subscriber obtained from MoreBodySubscribers.ofDeferredObject(TypeRef, MediaType). The media type is parsed from the Content-Type response header if present. The response is completed as soon as headers are received.
        Throws:
        java.lang.UnsupportedOperationException - if no BodyAdapter.Decoder that supports the given type is installed
      • decoding

        public static <T> java.net.http.HttpResponse.BodyHandler<T> decoding​(java.net.http.HttpResponse.BodyHandler<T> downstreamBodyHandler)
        Returns a BodyHandler that decompresses the response body for the given handler using a BodyDecoder. The decoder is created using the factory corresponding to the response's Content-Encoding header, throwing an UnsupportedOperationException if no such factory is installed. If the header is not present, the result of the given handler is returned as is.

        If the response is compressed, the Content-Encoding and Content-Length headers are stripped before forwarding the ResponseInfo to the given handler.

      • decoding

        public static <T> java.net.http.HttpResponse.BodyHandler<T> decoding​(java.net.http.HttpResponse.BodyHandler<T> downstreamHandler,
                                                                             @Nullable java.util.concurrent.Executor executor)
        Returns a BodyHandler that decompresses the response body for the given handler using a BodyDecoder. The decoder is created using the factory corresponding to the response's Content-Encoding header, throwing an UnsupportedOperationException if no such factory is installed. If the header is not present, the result of the given handler is returned as is.

        If the response is compressed, the Content-Encoding and Content-Length headers are stripped before forwarding the ResponseInfo to the given handler.