Search in sources :

Example 1 with NioWriteEntity

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);
}
Also used : Message(org.apache.cxf.message.Message) NioWriteEntity(org.apache.cxf.jaxrs.nio.NioWriteEntity) NioWriteListenerImpl(org.apache.cxf.jaxrs.nio.NioWriteListenerImpl) NioOutputStream(org.apache.cxf.jaxrs.nio.NioOutputStream)

Example 2 with NioWriteEntity

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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NioWriteEntity(org.apache.cxf.jaxrs.nio.NioWriteEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NioWriteEntity (org.apache.cxf.jaxrs.nio.NioWriteEntity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 NioOutputStream (org.apache.cxf.jaxrs.nio.NioOutputStream)1 NioWriteListenerImpl (org.apache.cxf.jaxrs.nio.NioWriteListenerImpl)1 Message (org.apache.cxf.message.Message)1