use of org.apache.cxf.jaxrs.nio.NioReadEntity in project cxf by apache.
the class NioBookStore method uploadBookStream.
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public void uploadBookStream(@Suspended AsyncResponse response) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final byte[] buffer = new byte[4096];
final LongAdder adder = new LongAdder();
new NioReadEntity(// read handler
in -> {
final int n = in.read(buffer);
if (n > 0) {
adder.add(n);
out.write(buffer, 0, n);
}
}, // completion handler
() -> {
closeOutputStream(out);
response.resume("Book Store uploaded: " + adder.longValue() + " bytes");
});
}
Aggregations