use of org.apache.cxf.jaxrs.nio.NioWriteEntity in project cxf by apache.
the class BinaryDataProvider method copyUsingNio.
protected void copyUsingNio(InputStream is, OutputStream os, Continuation cont) {
NioWriteListenerImpl listener = new NioWriteListenerImpl(cont, new NioWriteEntity(getNioHandler(is), null), new NioOutputStream(os));
Message m = JAXRSUtils.getCurrentMessage();
m.put(WriteListener.class, listener);
cont.suspend(0);
}
use of org.apache.cxf.jaxrs.nio.NioWriteEntity in project cxf by apache.
the class NioBookStore method getBookStream.
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getBookStream() throws IOException {
final ByteArrayInputStream in = new ByteArrayInputStream(IOUtils.readBytesFromStream(getClass().getResourceAsStream("/files/books.txt")));
final byte[] buffer = new byte[4096];
return Response.ok().entity(new NioWriteEntity(out -> {
final int n = in.read(buffer);
if (n >= 0) {
out.write(buffer, 0, n);
return true;
}
closeInputStream(in);
return false;
})).build();
}
Aggregations