Interface HttpDeframer<T>
- All Superinterfaces:
org.reactivestreams.Processor<HttpObject,T>
,org.reactivestreams.Publisher<T>
,StreamMessage<T>
,org.reactivestreams.Subscriber<HttpObject>
@UnstableApi public interface HttpDeframer<T> extends org.reactivestreams.Processor<HttpObject,T>, StreamMessage<T>
A
Processor
implementation that decodes a stream of HttpObject
s to N objects.
Follow the below steps to deframe HTTP payload using HttpDeframer
.
- Implement your deframing logic in
HttpDeframerHandler
.> class FixedLengthDecoder implements HttpDeframerHandler<String> { > private final int length; > > FixedLengthDecoder(int length) { > this.length = length; > } > > @Override > public void process(HttpDeframerInput in, HttpDeframerOutput<String> out) { > int remaining = in.readableBytes(); > if (remaining < length) { > // The input is not enough to process. Waiting for more data. > return; > } > > do { > // Read data from 'HttpDeframerInput' and > // write the processed result to 'HttpDeframerOutput'. > ByteBuf buf = in.readBytes(length); > out.add(buf.toString(StandardCharsets.UTF_8)); > // Should release the returned 'ByteBuf' > buf.release(); > remaining -= length; > } while (remaining >= length); > } > }
- Create an
HttpDeframer
with theHttpDeframerHandler
instance.FixedLengthDecoder decoder = new FixedLengthDecoder(11); HttpDeframer<String> deframer = HttpDeframer.of(decoder, ByteBufAllocator.DEFAULT);
- Subscribe to an
HttpRequest
using theHttpDeframer
.HttpRequest request = ...; request.subscribe(deframer);
- Subscribe to the
Publisher
of the deframed data and connect to your business logic.import reactor.core.publisher.Flux; Flux.from(deframer).map(...); // Consume and manipulate the deframed data.
-
Method Summary
Static Methods Modifier and Type Method Description static <T> HttpDeframer<T>
of(HttpDeframerHandler<T> handler, ByteBufAllocator alloc)
static <T> HttpDeframer<T>
of(HttpDeframerHandler<T> handler, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)
Returns a newHttpDeframer
with the specifiedHttpDeframerHandler
,ByteBufAllocator
andbyteBufConverter
.Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
abort, abort, defaultSubscriberExecutor, isComplete, isEmpty, isOpen, subscribe, subscribe, subscribe, subscribe, toDuplicator, toDuplicator, whenComplete
-
Method Details
-
of
-
of
static <T> HttpDeframer<T> of(HttpDeframerHandler<T> handler, ByteBufAllocator alloc, Function<? super HttpData,? extends ByteBuf> byteBufConverter)Returns a newHttpDeframer
with the specifiedHttpDeframerHandler
,ByteBufAllocator
andbyteBufConverter
.
-