use of io.helidon.common.reactive.OutputStreamMulti in project helidon by oracle.
the class HelidonEntity method submit.
/**
* Convert Jersey {@code OutputStream} to an entity based on the client request use case and submits to the provided
* {@code WebClientRequestBuilder}.
* @param type the type of the Helidon entity.
* @param requestContext Jersey {@link ClientRequest} providing the entity {@code OutputStream}.
* @param requestBuilder Helidon {@code WebClientRequestBuilder} which is used to submit the entity
* @param executorService {@link ExecutorService} that fills the entity instance for Helidon with data from Jersey
* {@code OutputStream}.
* @return Helidon Client response completion stage.
*/
static CompletionStage<WebClientResponse> submit(HelidonEntityType type, ClientRequest requestContext, WebClientRequestBuilder requestBuilder, ExecutorService executorService) {
CompletionStage<WebClientResponse> stage = null;
if (type != null) {
final int bufferSize = requestContext.resolveProperty(ClientProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 8192);
switch(type) {
case BYTE_ARRAY_OUTPUT_STREAM:
final ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);
requestContext.setStreamProvider(contentLength -> baos);
((ProcessingRunnable) requestContext::writeEntity).run();
stage = requestBuilder.submit(baos);
break;
case READABLE_BYTE_CHANNEL:
final OutputStreamChannel channel = new OutputStreamChannel(bufferSize);
requestContext.setStreamProvider(contentLength -> channel);
executorService.execute((ProcessingRunnable) requestContext::writeEntity);
stage = requestBuilder.submit(channel);
break;
case OUTPUT_STREAM_MULTI:
final OutputStreamMulti publisher = IoMulti.outputStreamMulti();
requestContext.setStreamProvider(contentLength -> publisher);
executorService.execute((ProcessingRunnable) () -> {
requestContext.writeEntity();
publisher.close();
});
stage = requestBuilder.submit(Multi.create(publisher).map(DataChunk::create));
break;
default:
}
}
return stage;
}
use of io.helidon.common.reactive.OutputStreamMulti in project metro-jax-ws by eclipse-ee4j.
the class HelidonConnectionImpl method getOutput.
@Override
public OutputStream getOutput() throws IOException {
OutputStreamMulti os = IoMulti.outputStreamMulti();
res.send(os.map(byteBuffer -> DataChunk.create(false, true, byteBuffer)));
return os;
}
Aggregations