/** * Transmit each set of bytes emitted by the publisher as a chunk. * <p> * The content type of the response is set to the given content type. * * @param contentType the value for the content-type header * @param publisher a publisher of byte buffers * @return a renderable object */ public static ResponseChunks bufferChunks(CharSequence contentType, Publisher<? extends ByteBuf> publisher) { return new ResponseChunks(contentType, byteBufAllocator -> publisher); }
/** * Transmit each string emitted by the publisher as a chunk. * <p> * The content type of the response is set to the given content type and each string is decoded as the given charset. * * @param contentType the value for the content-type header * @param charset the charset to use to decode each string chunk * @param publisher a publisher of strings * @return a renderable object */ public static ResponseChunks stringChunks(CharSequence contentType, Charset charset, Publisher<? extends CharSequence> publisher) { return new ResponseChunks(contentType, allocator -> Streams.map(publisher, charSequence -> ByteBufUtil.encodeString(allocator, CharBuffer.wrap(charSequence), charset) ) ); }