use of io.micronaut.core.async.annotation.SingleResult in project micronaut-core by micronaut-projects.
the class UploadController method publisherCompletedPart.
@Post(value = "/publisher-completedpart", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
@SingleResult
public Publisher<String> publisherCompletedPart(Publisher<CompletedPart> recipients) {
return Mono.create(emitter -> {
recipients.subscribe(new Subscriber<CompletedPart>() {
private Subscription s;
List<String> datas = new ArrayList<>();
@Override
public void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
public void onNext(CompletedPart data) {
try {
datas.add(new String(data.getBytes(), StandardCharsets.UTF_8));
s.request(1);
} catch (IOException e) {
s.cancel();
emitter.error(e);
}
}
@Override
public void onError(Throwable t) {
emitter.error(t);
}
@Override
public void onComplete() {
emitter.success(String.join("|", datas));
}
});
});
}
use of io.micronaut.core.async.annotation.SingleResult in project micronaut-core by micronaut-projects.
the class UploadController method receiveBigAttribute.
@Post(value = "/receive-big-attribute", consumes = MediaType.MULTIPART_FORM_DATA, produces = MediaType.TEXT_PLAIN)
@SingleResult
public Publisher<HttpResponse> receiveBigAttribute(Publisher<PartData> data) {
return Mono.create(emitter -> {
data.subscribe(new Subscriber<PartData>() {
private Subscription s;
List<String> datas = new ArrayList<>();
@Override
public void onSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
public void onNext(PartData data) {
try {
datas.add(new String(data.getBytes(), StandardCharsets.UTF_8));
s.request(1);
} catch (IOException e) {
s.cancel();
emitter.error(e);
}
}
@Override
public void onError(Throwable t) {
emitter.error(t);
}
@Override
public void onComplete() {
emitter.success(HttpResponse.ok(String.join("", datas)));
}
});
});
}
Aggregations