Module methanol

Interface BodyDecoder<T>

Type Parameters:
T - the subscriber's body type
All Superinterfaces:
Flow.Subscriber<List<ByteBuffer>>, HttpResponse.BodySubscriber<T>
All Known Implementing Classes:
AsyncBodyDecoder

public interface BodyDecoder<T> extends 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 (that is, downstream's onXXXX methods are dispatched to the executor). 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.

  • Method Details

    • encoding

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

      Optional<Executor> executor()
      Returns an Optional containing this decoder's executor. An empty optional is returned if the decoder is in "synchronous" mode.
    • downstream

      Returns this decoder's downstream.
    • getBody

      default CompletionStage<T> getBody()
      Returns the body's CompletionStage.

      Since this subscriber only acts as a processing stage, the default implementation simply returns the body completion stage of the downstream.

      Specified by:
      getBody in interface HttpResponse.BodySubscriber<T>