Example usage for javax.servlet.http HttpServletResponse getOutputStream

List of usage examples for javax.servlet.http HttpServletResponse getOutputStream

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getOutputStream.

Prototype

public ServletOutputStream getOutputStream() throws IOException;

Source Link

Document

Returns a ServletOutputStream suitable for writing binary data in the response.

Usage

From source file:com.xumpy.thuisadmin.controllers.rest.CtrlDocumenten.java

@RequestMapping(value = "/json/fetch_document/{documentId}", method = RequestMethod.GET)
public @ResponseBody String fetchDocumentBlob(@PathVariable Integer documentId, HttpServletResponse response)
        throws IOException, SQLException {
    OutputStream out = response.getOutputStream();
    Documenten documenten = documentenSrv.fetchDocument(documentId);

    response.setContentType(documenten.getDocument_mime());
    response.setHeader("Content-Disposition", "inline;filename=\"" + documenten.getDocument_naam() + "\"");

    out.write(documenten.getDocument());

    out.flush();//from   w ww.  j  ava  2s .com
    out.close();

    return null;
}

From source file:net.mindengine.blogix.web.BlogixServlet.java

private void printResponseText(HttpServletResponse res, String responseText) {
    try {/*from  ww  w. j a  va  2  s.c o m*/
        IOUtils.write(responseText, res.getOutputStream());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.lightadmin.core.web.support.FileResourceLoader.java

public void downloadFile(Object entity, PersistentProperty<?> persistentProperty, HttpServletResponse response)
        throws IOException {
    final long size = fileResourceStorage.copy(entity, persistentProperty, response.getOutputStream());
    final String eTag = eTag(entity.getClass(), persistentProperty.getName(), size);

    addImageResourceHeaders(response, octetStreamResponseHeader(APPLICATION_OCTET_STREAM, size, eTag));
}

From source file:org.magnum.dataup.VideoUpController.java

private void serveVideo(Video v, HttpServletResponse resp) throws IOException {
    videoDataMgr.copyVideoData(v, resp.getOutputStream());
}

From source file:eionet.web.action.SchemasRdfActionBean.java

/**
 * Handles the request for viewing VoID.
 *
 * @return// w  w w.jav  a  2  s .  c  o  m
 */
@DefaultHandler
public Resolution getRdf() {
    contextRoot = StringUtils.substringBeforeLast(getContext().getRequest().getRequestURL().toString(), "/");

    StreamingResolution result = new StreamingResolution("application/xml") {
        public void stream(HttpServletResponse response) throws Exception {
            SchemasManifestXmlWriter xmlWriter = new SchemasManifestXmlWriter(response.getOutputStream(),
                    contextRoot, schemaService);
            xmlWriter.writeManifestXml();
        }
    };
    return result;
}

From source file:action.ImageResult.java

public void execute(ActionInvocation invocation) throws IOException {
    ImageAction action = (ImageAction) invocation.getAction();
    HttpServletResponse response = ServletActionContext.getResponse();
    ServletOutputStream sos = response.getOutputStream();
    BufferedOutputStream output = null;
    byte[] imgBytes = action.getCustomImageInBytes();
    System.out.println("imgBytes--->" + imgBytes.toString());

    response.reset();/*from   www .j  ava 2  s . com*/
    response.setBufferSize(10240);
    response.setContentType("image/png");
    response.setContentLength(action.getCustomImageInBytes().length);
    response.setHeader("Content-Disposition", "inline; filename=\"sss\"");
    //response.getOutputStream().write(action.getCustomImageInBytes());
    // response.getOutputStream().flush();
    try {
        output = new BufferedOutputStream(response.getOutputStream(), 10240);
        output.write(imgBytes);
    } finally {
        // Gently close streams.
        if (output != null) {
            try {
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.opensafety.hishare.view.ByteOutput.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    byte[] data = (byte[]) model.get("bytes");

    response.setContentType("application/octet-stream");
    response.getOutputStream().write(data);
    response.getOutputStream().flush();//w ww . j  a v a 2  s  .  c  om
}

From source file:com.thoughtworks.go.server.web.FileView.java

private void setOutput(boolean needToZip, File file, HttpServletResponse response) throws IOException {
    ServletOutputStream out = response.getOutputStream();
    if (needToZip) {
        new ZipUtil().zip(file, out, Deflater.NO_COMPRESSION);
    } else {/*from  www .jav  a  2s  .c o  m*/
        try (FileInputStream input = new FileInputStream(file)) {
            IOUtils.copy(input, out, 32 * 1024);
        }
    }
    out.flush();
}

From source file:net.jadler.stubbing.server.jetty.StubHandler.java

private void writeResponseBody(final byte[] body, final HttpServletResponse response) throws IOException {
    if (body.length > 0) {
        final ServletOutputStream os = response.getOutputStream();
        os.write(body);/*ww  w .ja v a  2  s.c  o m*/
    }
}

From source file:com.thoughtworks.go.server.web.XmlView.java

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    Document document = (Document) model.get("document");
    ServletOutputStream outputStream = response.getOutputStream();
    try {/*from w  w  w .  j av  a  2s  . c  o m*/
        XmlUtils.writeXml(document, outputStream);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}