Class DocumentDataConsumer<T>

java.lang.Object
io.camunda.client.impl.http.DocumentDataConsumer<T>
Type Parameters:
T - the type of the successful response body, always an InputStream
All Implemented Interfaces:
CircularBufferInputStream.CapacityCallback, org.apache.hc.core5.http.nio.AsyncDataConsumer, org.apache.hc.core5.http.nio.AsyncEntityConsumer<ApiEntity<T>>, org.apache.hc.core5.http.nio.ResourceHolder

public class DocumentDataConsumer<T> extends Object implements org.apache.hc.core5.http.nio.AsyncEntityConsumer<ApiEntity<T>>, CircularBufferInputStream.CapacityCallback
An asynchronous consumer for binary data that represents a document.

This implementation guarantees that the data is consumed in a non-blocking manner, and that the data is stored in a buffer with a fixed capacity. The consumer works with a CapacityChannel to notify the I/O layer when more data can be read from the network.

If the server returns:

  • application/octet-stream: the data is returned as an InputStream
  • application/problem+json: the data is returned as a ProblemDetail
Anything else will cause an error to be propagated to the caller.

The input stream response is returned via the result callback immediately as soon as the content type is determined to be application/octet-stream. This allows the caller to start reading the data in a streaming fashion and does not require the entire response body to be buffered in memory.

  • Constructor Details

    • DocumentDataConsumer

      public DocumentDataConsumer(int bufferCapacity, com.fasterxml.jackson.databind.ObjectMapper json)
  • Method Details

    • streamStart

      public void streamStart(org.apache.hc.core5.http.EntityDetails entityDetails, org.apache.hc.core5.concurrent.FutureCallback<ApiEntity<T>> resultCallback)
      Specified by:
      streamStart in interface org.apache.hc.core5.http.nio.AsyncEntityConsumer<T>
    • failed

      public void failed(Exception cause)
      Specified by:
      failed in interface org.apache.hc.core5.http.nio.AsyncEntityConsumer<T>
    • getContent

      public ApiEntity<T> getContent()
      Specified by:
      getContent in interface org.apache.hc.core5.http.nio.AsyncEntityConsumer<T>
    • updateCapacity

      public void updateCapacity(org.apache.hc.core5.http.nio.CapacityChannel capacityChannel) throws IOException
      Specified by:
      updateCapacity in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
      Throws:
      IOException
    • consume

      public void consume(ByteBuffer src) throws IOException
      Specified by:
      consume in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
      Throws:
      IOException
    • streamEnd

      public void streamEnd(List<? extends org.apache.hc.core5.http.Header> trailers) throws IOException
      Specified by:
      streamEnd in interface org.apache.hc.core5.http.nio.AsyncDataConsumer
      Throws:
      IOException
    • releaseResources

      public void releaseResources()
      Specified by:
      releaseResources in interface org.apache.hc.core5.http.nio.ResourceHolder
    • onCapacityAvailable

      public void onCapacityAvailable(int increment)
      Specified by:
      onCapacityAvailable in interface CircularBufferInputStream.CapacityCallback