- java.lang.Object
-
- io.helidon.media.common.MessageBodyReadableContent
-
- All Implemented Interfaces:
Content,Multi<DataChunk>,Subscribable<DataChunk>,MessageBodyContent,MessageBodyFilters,MessageBodyReaders,Flow.Publisher<DataChunk>
public final class MessageBodyReadableContent extends Object implements MessageBodyReaders, MessageBodyFilters, MessageBodyContent, Content
ReadableMessageBodyContent.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> Single<T>as(GenericType<T> type)Consumes and converts the content payload into a completion stage of the requested type.<T> Single<T>as(Class<T> type)Consumes and converts the request content into a completion stage of the requested type.<T> Multi<T>asStream(GenericType<T> type)Consumes and converts the content payload into a stream of entities of the requested type.<T> Multi<T>asStream(Class<T> type)Consumes and converts the content payload into a stream of entities of the requested type.static MessageBodyReadableContentcreate(Flow.Publisher<DataChunk> publisher, MessageBodyReaderContext context)Create a new readable content backed by the given publisher and context.MessageBodyReaderContextreaderContext()Get the reader context used to unmarshall data.MessageBodyReadableContentregisterFilter(MessageBodyFilter filter)Registers a message body filter.voidregisterFilter(Function<Flow.Publisher<DataChunk>,Flow.Publisher<DataChunk>> function)Deprecated.MessageBodyReadableContentregisterReader(MessageBodyReader<?> reader)Register a reader.MessageBodyReadableContentregisterReader(MessageBodyStreamReader<?> reader)Register a stream reader.<T> voidregisterReader(Class<T> type, Reader<T> reader)Deprecated.<T> voidregisterReader(Predicate<Class<?>> predicate, Reader<T> reader)Deprecated.voidsubscribe(Flow.Subscriber<? super DataChunk> subscriber)If possible, adds the given Subscriber to this publisher.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.helidon.common.reactive.Multi
collect, collect, collectList, collectStream, compose, defaultIfEmpty, defaultIfEmpty, distinct, dropWhile, filter, first, flatMap, flatMap, flatMapCompletionStage, flatMapIterable, flatMapIterable, flatMapOptional, forEach, ifEmpty, ignoreElements, limit, log, log, log, log, map, observeOn, observeOn, onCancel, onComplete, onCompleteResume, onCompleteResumeWith, onError, onErrorResume, onErrorResumeWith, onTerminate, peek, reduce, reduce, retry, retry, retryWhen, skip, switchIfEmpty, takeUntil, takeWhile, timeout, timeout, to
-
Methods inherited from interface io.helidon.common.reactive.Subscribable
subscribe, subscribe, subscribe, subscribe
-
-
-
-
Method Detail
-
readerContext
public MessageBodyReaderContext readerContext()
Get the reader context used to unmarshall data.- Returns:
- MessageBodyReaderContext
-
registerFilter
public MessageBodyReadableContent registerFilter(MessageBodyFilter filter)
Description copied from interface:MessageBodyFiltersRegisters 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:
registerFilterin interfaceMessageBodyFilters- Parameters:
filter- a function to map previously registered or originalPublisherto the new one. If returnsnullthen the result will be ignored.- Returns:
- this instance of
MessageBodyFilters - See Also:
MessageBodyContext.applyFilters(Flow.Publisher)
-
registerReader
public MessageBodyReadableContent registerReader(MessageBodyReader<?> reader)
Description copied from interface:MessageBodyReadersRegister a reader.- Specified by:
registerReaderin interfaceMessageBodyReaders- Parameters:
reader- reader to register- Returns:
- Readers
-
registerReader
public MessageBodyReadableContent registerReader(MessageBodyStreamReader<?> reader)
Description copied from interface:MessageBodyReadersRegister a stream reader.- Specified by:
registerReaderin interfaceMessageBodyReaders- Parameters:
reader- reader to register- Returns:
- Readers
-
registerFilter
@Deprecated public void registerFilter(Function<Flow.Publisher<DataChunk>,Flow.Publisher<DataChunk>> function)
Deprecated.Description copied from interface:ContentRegisters a filter that allows a control of the original publisher.The provided function is evaluated upon calling either of
Content.subscribe(Flow.Subscriber)orContent.as(Class). 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. It is up to the implementor of the given function to respect the contract of both the original publisher and the previously registered ones.- Specified by:
registerFilterin interfaceContent- Parameters:
function- a function that transforms a given publisher (that is either the original publisher or the publisher transformed by the last previously registered filter).
-
registerReader
@Deprecated public <T> void registerReader(Class<T> type, Reader<T> reader)
Deprecated.Description copied from interface:ContentRegisters a reader for a later use with an appropriateContent.as(Class)method call.The reader must transform the published byte buffers into a completion stage of the requested type.
Upon calling
Content.as(Class)a matching reader is searched in the same order as the readers were registered. If no matching reader is found, or when the function throws an exception, the resulting completion stage ends exceptionally.- Specified by:
registerReaderin interfaceContent- Type Parameters:
T- the requested type- Parameters:
type- the requested type the completion stage is be associated with.reader- the reader as a function that transforms a publisher into completion stage. If an exception is thrown, the resulting completion stage ofContent.as(Class)method call ends exceptionally.
-
registerReader
@Deprecated public <T> void registerReader(Predicate<Class<?>> predicate, Reader<T> reader)
Deprecated.Description copied from interface:ContentRegisters a reader for a later use with an appropriateContent.as(Class)method call.The reader must transform the published byte buffers into a completion stage of the requested type.
Upon calling
Content.as(Class)a matching reader is searched in the same order as the readers were registered. If no matching reader is found or when the predicate throws an exception, or when the function throws an exception, the resulting completion stage ends exceptionally.- Specified by:
registerReaderin interfaceContent- Type Parameters:
T- the requested type- Parameters:
predicate- the predicate that determines whether the registered reader can handle the requested type. If an exception is thrown, the resulting completion stage ofContent.as(Class)method call ends exceptionally.reader- the reader as a function that transforms a publisher into completion stage. If an exception is thrown, the resulting completion stage ofContent.as(Class)method call ends exceptionally.
-
subscribe
public void subscribe(Flow.Subscriber<? super DataChunk> subscriber)
Description copied from interface:ContentIf possible, adds the given Subscriber to this publisher. This publisher is effectively either the original publisher or the last publisher registered by the methodContent.registerFilter(Function).Note that the original publisher allows only a single subscriber and requires the passed
DataChunkin theFlow.Subscriber.onNext(Object)call to be consumed before the method completes as specified by theDefault Publisher Contract.- Specified by:
subscribein interfaceContent- Specified by:
subscribein interfaceFlow.Publisher<DataChunk>- Parameters:
subscriber- the subscriber
-
as
public <T> Single<T> as(Class<T> type)
Description copied from interface:ContentConsumes and converts the request content into a completion stage of the requested type.The conversion requires an appropriate reader to be already registered (see
Content.registerReader(Predicate, Reader)). 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
InputStreamit is highly recommended to do so out of the scope of reactive chain, or to use methods likeCompletionStage.thenAcceptAsync(Consumer, Executor).
-
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 publishercontext- reader context- Returns:
- MessageBodyReadableContent
-
-