Class MessageBodyReadableContent

java.lang.Object
io.helidon.reactive.media.common.MessageBodyReadableContent
All Implemented Interfaces:
Multi<DataChunk>, Subscribable<DataChunk>, MessageBodyContent, MessageBodyFilters, MessageBodyReaders, Flow.Publisher<DataChunk>

public final class MessageBodyReadableContent extends Object implements MessageBodyReaders, MessageBodyFilters, MessageBodyContent, Multi<DataChunk>
  • Method Details

    • readerContext

      public MessageBodyReaderContext readerContext()
      Get the reader context used to unmarshall data.
      Returns:
      MessageBodyReaderContext
    • registerFilter

      public MessageBodyReadableContent registerFilter(MessageBodyFilter filter)
      Description copied from interface: MessageBodyFilters
      Registers a message body filter.

      The registered filters are applied to form a chain from the first registered to the last registered. The first evaluation of the function transforms the original publisher to a new publisher. Any subsequent evaluation receives the publisher transformed by the last previously registered filter.

      Specified by:
      registerFilter in interface MessageBodyFilters
      Parameters:
      filter - a function to map previously registered or original Publisher to the new one. If returns null then the result will be ignored.
      Returns:
      this instance of MessageBodyFilters
      See Also:
    • registerReader

      public MessageBodyReadableContent registerReader(MessageBodyReader<?> reader)
      Description copied from interface: MessageBodyReaders
      Register a reader.
      Specified by:
      registerReader in interface MessageBodyReaders
      Parameters:
      reader - reader to register
      Returns:
      Readers
    • registerReader

      public MessageBodyReadableContent registerReader(MessageBodyStreamReader<?> reader)
      Description copied from interface: MessageBodyReaders
      Register a stream reader.
      Specified by:
      registerReader in interface MessageBodyReaders
      Parameters:
      reader - reader to register
      Returns:
      Readers
    • subscribe

      public void subscribe(Flow.Subscriber<? super DataChunk> subscriber)
      Specified by:
      subscribe in interface Flow.Publisher<DataChunk>
    • as

      public <T> Single<T> as(Class<T> type)
      Consumes and converts the request content into a completion stage of the requested type.

      The conversion requires an appropriate reader to be already registered (see registerReader(MessageBodyReader)). If no such reader is found, the resulting completion stage ends exceptionally.

      Any callback related to the returned value, should not be blocking. Blocking operation could cause deadlock. If you need to use blocking API such as InputStream it is highly recommended to do so out of the scope of reactive chain, or to use methods like CompletionStage.thenAcceptAsync(java.util.function.Consumer, java.util.concurrent.Executor).

      Type Parameters:
      T - the requested type
      Parameters:
      type - the requested type class
      Returns:
      a completion stage of the requested type
    • as

      public <T> Single<T> as(GenericType<T> type)
      Consumes and converts the content payload into a completion stage of the requested type.
      Type Parameters:
      T - the requested type
      Parameters:
      type - the requested type class
      Returns:
      a completion stage of the requested type
    • asStream

      public <T> Multi<T> asStream(Class<T> type)
      Consumes and converts the content payload into a stream of entities of the requested type.
      Type Parameters:
      T - the requested type
      Parameters:
      type - the requested type class
      Returns:
      a stream of entities
    • asStream

      public <T> Multi<T> asStream(GenericType<T> type)
      Consumes and converts the content payload into a stream of entities of the requested type.
      Type Parameters:
      T - the requested type
      Parameters:
      type - the requested type class
      Returns:
      a stream of entities
    • create

      public static MessageBodyReadableContent create(Flow.Publisher<DataChunk> publisher, MessageBodyReaderContext context)
      Create a new readable content backed by the given publisher and context.
      Parameters:
      publisher - content publisher
      context - reader context
      Returns:
      MessageBodyReadableContent