Example usage for org.springframework.web.servlet.mvc.method.annotation StreamingResponseBody StreamingResponseBody

List of usage examples for org.springframework.web.servlet.mvc.method.annotation StreamingResponseBody StreamingResponseBody

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.method.annotation StreamingResponseBody StreamingResponseBody.

Prototype

StreamingResponseBody

Source Link

Usage

From source file:com.graphaware.example.NodeStreamingApi.java

@RequestMapping(path = "v2", method = RequestMethod.GET)
public StreamingResponseBody streamV2() {

    return new StreamingResponseBody() {
        @Override//from  w  ww  .  ja va2  s  . c om
        public void writeTo(final OutputStream outputStream) throws IOException {
            JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(outputStream);
            jsonGenerator.writeStartArray();

            try (Transaction tx = database.beginTx()) {
                for (Node node : database.getAllNodes()) {
                    jsonGenerator.writeObject(new LongIdJsonNode(node));
                }
                tx.success();
            }

            jsonGenerator.writeEndArray();
            jsonGenerator.close();
        }
    };
}

From source file:uk.ac.ebi.eva.vcfdump.server.VcfDumperWSServer.java

private StreamingResponseBody getStreamingResponseBody(String species, String dbName, List<String> studies,
        Properties evaProperties, MultivaluedMap<String, String> queryParameters,
        HttpServletResponse response) {/*from  ww w .j a  va  2  s . c o  m*/

    return new StreamingResponseBody() {
        @Override
        public void writeTo(OutputStream outputStream) throws IOException, WebApplicationException {
            VariantExporterController controller;
            try {
                controller = new VariantExporterController(species, dbName, studies, outputStream,
                        evaProperties, queryParameters);
                // tell the client that the file is an attachment, so it will download it instead of showing it
                response.addHeader(HttpHeaders.CONTENT_DISPOSITION,
                        "attachment;filename=" + controller.getOutputFileName());
                controller.run();
            } catch (Exception e) {
                throw new WebApplicationException(e);
            }
        }
    };
}