- java.lang.Object
-
- com.github.mizosoft.methanol.MoreBodySubscribers
-
public class MoreBodySubscribers extends java.lang.ObjectStatic factories for additionalHttpResponse.BodySubscriberimplementations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,S extends java.util.concurrent.Flow.Subscriber<? super java.util.List<java.nio.ByteBuffer>>>
java.net.http.HttpResponse.BodySubscriber<T>fromAsyncSubscriber(S downstream, java.util.function.Function<? super S,? extends java.util.concurrent.CompletionStage<T>> asyncFinisher)Returns aBodySubscriberthat forwards the response body to the given downstream.static java.net.http.HttpResponse.BodySubscriber<java.nio.channels.ReadableByteChannel>ofByteChannel()Returns a completedBodySubscriberofReadableByteChannelthat reads the response body.static <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>>ofDeferredObject(TypeRef<T> type, @Nullable MediaType mediaType)Returns aBodySubscriberthat decodes the response body into an object of the given type using an installeddecoder.static <T> java.net.http.HttpResponse.BodySubscriber<T>ofObject(TypeRef<T> type, @Nullable MediaType mediaType)Returns aBodySubscriberthat decodes the response body into an object of the given type using an installeddecoder.static java.net.http.HttpResponse.BodySubscriber<java.io.Reader>ofReader(java.nio.charset.Charset charset)Returns a completedBodySubscriberofReaderthat reads the response body as a stream of characters decoded using the given charset.static <T> java.net.http.HttpResponse.BodySubscriber<T>withReadTimeout(java.net.http.HttpResponse.BodySubscriber<T> downstream, java.time.Duration timeout)Returns aBodySubscriberthat completes the given downstream withHttpReadTimeoutExceptionif a requested signal is not received within the given timeout.static <T> java.net.http.HttpResponse.BodySubscriber<T>withReadTimeout(java.net.http.HttpResponse.BodySubscriber<T> downstream, java.time.Duration timeout, java.util.concurrent.ScheduledExecutorService scheduler)Returns aBodySubscriberthat completes the given downstream withHttpReadTimeoutExceptionif a requested signal is not received within the given timeout.
-
-
-
Method Detail
-
fromAsyncSubscriber
public static <T,S extends java.util.concurrent.Flow.Subscriber<? super java.util.List<java.nio.ByteBuffer>>> java.net.http.HttpResponse.BodySubscriber<T> fromAsyncSubscriber(S downstream, java.util.function.Function<? super S,? extends java.util.concurrent.CompletionStage<T>> asyncFinisher)Returns aBodySubscriberthat forwards the response body to the given downstream. The response body's completion depends on the completion of theCompletionStagereturned by the given function. UnlikeHttpResponse.BodySubscribers.fromSubscriber(Subscriber, Function), the given subscriber'sonCompleteoronErrorneed not be called for the body to complete.
-
withReadTimeout
public static <T> java.net.http.HttpResponse.BodySubscriber<T> withReadTimeout(java.net.http.HttpResponse.BodySubscriber<T> downstream, java.time.Duration timeout)Returns aBodySubscriberthat completes the given downstream withHttpReadTimeoutExceptionif a requested signal is not received within the given timeout. A system-wide scheduler is used to schedule timeout events.- Throws:
java.lang.IllegalArgumentException- if the timeout is non-positive
-
withReadTimeout
public static <T> java.net.http.HttpResponse.BodySubscriber<T> withReadTimeout(java.net.http.HttpResponse.BodySubscriber<T> downstream, java.time.Duration timeout, java.util.concurrent.ScheduledExecutorService scheduler)Returns aBodySubscriberthat completes the given downstream withHttpReadTimeoutExceptionif a requested signal is not received within the given timeout. The givenScheduledExecutorServiceis used to schedule timeout events.- Throws:
java.lang.IllegalArgumentException- if the timeout is non-positive
-
ofByteChannel
public static java.net.http.HttpResponse.BodySubscriber<java.nio.channels.ReadableByteChannel> ofByteChannel()
Returns a completedBodySubscriberofReadableByteChannelthat reads the response body. The channel returned by the subscriber isinterruptible.To ensure proper release of resources, the channel should be fully consumed until EOF is reached. If such consumption cannot be guaranteed, either the channel should be eventually closed or the thread which is blocked on reading the channel should be interrupted. Note, however, that doing so will render the underlying connection unusable for subsequent requests.
-
ofReader
public static java.net.http.HttpResponse.BodySubscriber<java.io.Reader> ofReader(java.nio.charset.Charset charset)
Returns a completedBodySubscriberofReaderthat reads the response body as a stream of characters decoded using the given charset.To ensure proper release of resources, the reader should be fully consumed until EOF is reached. If such consumption cannot be guaranteed, the reader should be eventually closed. Note, however, that doing so will render the underlying connection unusable for subsequent requests.
-
ofObject
public static <T> java.net.http.HttpResponse.BodySubscriber<T> ofObject(TypeRef<T> type, @Nullable MediaType mediaType)
Returns aBodySubscriberthat decodes the response body into an object of the given type using an installeddecoder.- Throws:
java.lang.UnsupportedOperationException- if noBodyAdapter.Decoderthat supports the given object type or media type is installed
-
ofDeferredObject
public static <T> java.net.http.HttpResponse.BodySubscriber<java.util.function.Supplier<T>> ofDeferredObject(TypeRef<T> type, @Nullable MediaType mediaType)
Returns aBodySubscriberthat decodes the response body into an object of the given type using an installeddecoder.- Throws:
java.lang.UnsupportedOperationException- if noBodyAdapter.Decoderthat supports the given object type or media type is installed
-
-