Module methanol

Interface BodyDecoder<T>

  • Type Parameters:
    T - the subscriber's body type
    All Superinterfaces:
    java.util.concurrent.Flow.Subscriber<java.util.List<java.nio.ByteBuffer>>, java.net.http.HttpResponse.BodySubscriber<T>
    All Known Implementing Classes:
    AsyncBodyDecoder

    public interface BodyDecoder<T>
    extends java.net.http.HttpResponse.BodySubscriber<T>
    A HttpResponse.BodySubscriber that decodes the response body for consumption by a downstream subscriber. Despite not implementing the interface, a BodyDecoder has the same semantics of a Processor<List<ByteBuffer>, List<ByteBuffer>>. It takes lists of ByteBuffers from the HTTP client, then publishes their decompressed form to the downstream subscriber, which itself converts the former to the desired high-level type.

    The guarantees given by the HTTP client are also given by the decoder; the downstream receives a strictly ordered representation of the decoded response body in the form of immutable lists of read-only ByteBuffers, which up on being passed, are no longer referenced by the decoder.

    Optionally, a BodyDecoder can have an Executor. If present, the executor is used to deliver downstream signals. This can lead to overlapped processing between the two subscribers. If an executor is not present, the decoder processes and supplies downstream items in the same thread, which is normally the upstream thread supplying the compressed ByteBuffers.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  BodyDecoder.Factory
      A factory of BodyDecoder instances for some defined encoding.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.net.http.HttpResponse.BodySubscriber<T> downstream()
      Returns this decoder's downstream.
      java.lang.String encoding()
      Returns the encoding used by this decoder.
      java.util.Optional<java.util.concurrent.Executor> executor()
      Returns this decoder's executor if one is specified.
      default java.util.concurrent.CompletionStage<T> getBody()
      Returns the body's CompletionStage.
      • Methods inherited from interface java.util.concurrent.Flow.Subscriber

        onComplete, onError, onNext, onSubscribe
    • Method Detail

      • encoding

        java.lang.String encoding()
        Returns the encoding used by this decoder. This corresponds to the value of the Content-Type header.
      • executor

        java.util.Optional<java.util.concurrent.Executor> executor()
        Returns this decoder's executor if one is specified.
      • downstream

        java.net.http.HttpResponse.BodySubscriber<T> downstream()
        Returns this decoder's downstream.
      • getBody

        default java.util.concurrent.CompletionStage<T> getBody()
        Returns the body's CompletionStage.
        Specified by:
        getBody in interface java.net.http.HttpResponse.BodySubscriber<T>