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.stratelia.webactiv.kmelia.servlets.AliasFileServer.java

private void displayWarningHtmlCode(HttpServletResponse res) throws IOException {
    OutputStream out = res.getOutputStream();
    ResourceLocator resourceLocator = new ResourceLocator(
            "org.silverpeas.util.peasUtil.multiLang.fileServerBundle", "");

    InputStream in = new ByteArrayInputStream(resourceLocator.getString("warning").getBytes(Charsets.UTF_8));
    try {/*from w ww. j  ava  2 s .c o  m*/
        IOUtils.copy(in, out);
    } catch (Exception e) {
        SilverTrace.warn("kmelia", "AliasFileServer.displayWarningHtmlCode", "root.EX_CANT_READ_FILE",
                "warning properties");
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.SparqlQueryBuilderServlet.java

private void doNoModelInContext(HttpServletRequest request, HttpServletResponse res) {
    try {/*from  w w  w  .  jav a2 s .c o  m*/
        res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        ServletOutputStream sos = res.getOutputStream();
        sos.println("<html><body>this service is not supporeted by the current "
                + "webapp configuration. A jena model is required in the servlet context.</body></html>");
    } catch (IOException e) {
        log.error("Could not write to ServletOutputStream");
    }
}

From source file:edu.txstate.dmlab.clusteringwiki.rest.BaseRestController.java

/**
 * Send output back to the browser/*from w ww  .j a va2 s  .  c  om*/
 * @param response
 * @param resp
 */
protected void sendOutput(HttpServletResponse response, String resp) {
    try {
        response.getOutputStream().write(resp.getBytes());
        response.flushBuffer();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:nl.tue.gale.ae.JSONServlet.java

private void reply(String s, HttpServletResponse resp) throws IOException {
    resp.setBufferSize(8192);//www .  ja  va 2  s  . c om
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
    bw.write(s);
    bw.close();
}

From source file:com.expressflow.servlets.ExecProcessServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    performRequest(request, response);//  w  w w  .  j a  v a  2 s  .c o  m
    try {
        response.getOutputStream().println(new JSONObject().put("result", "success").toString());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(System.err);
    }
}

From source file:dijalmasilva.controllers.ControladorIdolo.java

@RequestMapping("/image/{id}")
public void carregaImagem(@PathVariable Long id, HttpServletResponse resp) {
    ServletOutputStream out = null;/*  w w w. j a v a2 s .  c  o  m*/
    try {
        Idolo idolo = serviceIdolo.buscar(id);
        out = resp.getOutputStream();
        out.write(idolo.getFoto());
        out.flush();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:fi.okm.mpass.shibboleth.profile.impl.WriteMonitoringResult.java

/**
 * Writes the given message to the servlet response and returns a Spring webflow event.
 * @param httpResponse The servlet response.
 * @param message The message to be written to the servlet response.
 * @return The proceed event if the action was successful, IO_ERROR otherwise.
 *//*from   ww  w.j a va 2  s  .c om*/
protected Event writeAndReturn(final HttpServletResponse httpResponse, final String message) {
    try {
        final Writer out = new OutputStreamWriter(httpResponse.getOutputStream(), "UTF-8");
        out.append(message);
        out.flush();
    } catch (IOException e) {
        log.error("{}: Could not encode the JSON response", getLogPrefix(), e);
        httpResponse.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
        return ActionSupport.buildEvent(this, EventIds.IO_ERROR);
    }
    return ActionSupport.buildProceedEvent(this);
}

From source file:org.overlord.apiman.gateway.http.HTTPGateway.java

/** Copy response body data (the entity) from the proxy to the servlet client. */
protected void copyResponseContent(Response proxyResponse, HttpServletResponse servletResponse)
        throws IOException {
    OutputStream servletOutputStream = servletResponse.getOutputStream();

    try {/*from ww w . j  a  v  a  2s.c om*/
        servletOutputStream.write(proxyResponse.getContent());

    } finally {
        try {
            //is.close();
            servletOutputStream.close();
        } catch (Exception e) {
            log(e.getMessage(), e);
        }
    }
}

From source file:com.actionbazaar.image.ImageServlet.java

/**
 * Retrieves the specified image//from  w  w w  . j av  a  2 s .c  om
 * @param req - request
 * @param resp - response
 * @throws ServletException - thrown if there is an error
 * @throws IOException - another exception
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("image/png");
    OutputStream outStream;
    outStream = resp.getOutputStream();
    InputStream is;
    String name = req.getParameter("name");
    if (name == null) {
        is = ImageServlet.class.getResourceAsStream("/com/actionbazaar/blank.png");
    } else {
        ImageRecord imageRecord = imageBean.getFile(name);
        if (imageRecord != null) {
            is = new BufferedInputStream(new FileInputStream(imageRecord.getThumbnailFile()));
        } else {
            is = ImageServlet.class.getResourceAsStream("/com/actionbazaar/blank.png");
        }
    }
    IOUtils.copy(is, outStream);
    outStream.close();
    outStream.flush();
}

From source file:com.qcadoo.mes.workPlans.controller.WorkPlansController.java

private void printImageToPdf(final Entity attachment, HttpServletResponse response) {
    Document document = new Document();
    try {//from   w  w  w . ja  v a  2 s  .c  om
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        document.setPageSize(PageSize.A4);
        pdfHelper.addMetaData(document);
        pdfHelper.addImage(document, attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));
        document.close();
    } catch (Exception e) {
        LOG.error("Problem with printing document - " + e.getMessage());
        document.close();
        e.printStackTrace();
    }

}