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.vh.ds.iam.web.front.jxl.AbstractJxlView.java

/**
 * Renders the Excel view, given the specified model.
 *///from   w  w w .  ja v a 2 s .co  m
@Override
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // Set the content type and get the output stream.
    response.setContentType(getContentType());
    OutputStream out = response.getOutputStream();

    WorkbookSettings ws = new WorkbookSettings();
    ws.setEncoding("Cp1252");

    WritableWorkbook workbook;
    if (this.url != null) {
        Workbook template = getTemplateSource(this.url, request);
        workbook = Workbook.createWorkbook(out, template, ws);
    } else {
        LOGGER.debug("Creating Excel Workbook from scratch");
        workbook = Workbook.createWorkbook(out, ws);
    }

    buildExcelDocument(model, workbook, request, response);

    workbook.write();
    out.flush();
    workbook.close();
}

From source file:dijalmasilva.controllers.ControladorUser.java

@RequestMapping("/image/{id}")
public void carregaImagem(@PathVariable Long id, HttpServletResponse resp) {
    ServletOutputStream out = null;//from  www. j  a  v a2 s .  co m
    try {
        Usuario usuario = serviceUser.findById(id);
        out = resp.getOutputStream();
        out.write(usuario.getFoto());
        out.flush();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.cubusmail.server.services.CubusmailServlet.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String fileName = request.getSession().getServletContext().getRealPath(request.getServletPath());
    BufferedReader reader = new BufferedReader(new FileReader(fileName));

    OutputStream outputStream = response.getOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(outputStream);
    char[] inBuf = new char[1024];
    int len = 0;// ww w . ja  v a  2  s.c  om
    try {
        while ((len = reader.read(inBuf)) > 0) {
            writer.write(inBuf, 0, len);
        }
    } catch (Throwable e) {
        log.error(e.getMessage(), e);
    }

    writer.flush();
    writer.close();
    outputStream.flush();
    outputStream.close();
}

From source file:com.liferay.arquillian.DeployerServlet.java

private void signalError(Throwable t, HttpServletResponse response) {
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    try {// w  w w . jav a2s.  co m
        ServletOutputStream outputStream = response.getOutputStream();

        response.setContentType(StringPool.UTF8);

        PrintWriter printWriter = new PrintWriter(outputStream);

        t.printStackTrace(printWriter);

        printWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.silverpeas.silvercrawler.servlets.SilverCrawlerFileServer.java

private void displayWarningHtmlCode(HttpServletResponse res) throws IOException {
    ResourceLocator resourceLocator = new ResourceLocator(
            "com.stratelia.webactiv.util.peasUtil.multiLang.fileServerBundle", "");

    OutputStream out = res.getOutputStream();
    StringReader sr = new StringReader(resourceLocator.getString("warning"));
    try {/*from ww w.  j  a  v a2  s .co m*/
        IOUtils.copy(sr, out);
        out.flush();
    } catch (IOException e) {
        SilverTrace.warn("silverCrawler", "FileServer.displayWarningHtmlCode", "root.EX_CANT_READ_FILE",
                "warning properties");
    } finally {
        IOUtils.closeQuietly(sr);
        IOUtils.closeQuietly(out);
    }
}

From source file:com.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java

protected void getAll(HttpServletRequest request, HttpServletResponse response)
        throws IOException, JDOMException {
    response.setContentType("text/xml");
    prettyXmlOutputter.output(scoreBoardModel.getXmlScoreBoard().getDocument(), response.getOutputStream());
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.gu.management.switching.SwitchboardServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/html");

    String switchToShow = request.getParameter("switch");

    OutputStreamWriter fileWriter = new OutputStreamWriter(response.getOutputStream());

    fileWriter.write(MANAGEMENT_PAGE_HEAD);

    for (Switchable switchable : switches) {

        if (StringUtils.isEmpty(switchToShow) || switchToShow.equals(switchable.getWordForUrl())) {
            fileWriter.write(String.format(SWITCH_TABLE_ROW, switchable.getWordForUrl(),
                    switchable.getDescription(), getButtonsFor(switchable)));
        }//  ww w. ja v a  2  s . c o  m
    }

    fileWriter.write(MANAGEMENT_PAGE_FOOT);

    fileWriter.flush();
}

From source file:com.impala.paga.all.RouteRemit1.java

/**
 * /* ww w . ja  v a 2 s  .  c o m*/
 * @param request
 * @param response
 * @throws ServletException
 *             , IOException
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    OutputStream out = response.getOutputStream();

    response.setContentType("text/plain;charset=UTF-8");
    response.setDateHeader("Expires", new Date().getTime()); // Expiration
    // date
    response.setDateHeader("Date", new Date().getTime()); // Date and time
    try {
        // that the
        // message was
        // sent
        out.write(moneytransfer(request).getBytes());
    } catch (JSONException ex) {
        Logger.getLogger(RouteRemit1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(RouteRemit1.class.getName()).log(Level.SEVERE, null, ex);
    }
    out.flush();
    out.close();
}

From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSealedPdf.java

/**
 * Send the PDF to the http response//from   ww  w  .  ja  v  a  2  s . com
 * @param is the stream containing the PDF
 * @param pdfName the name of the PDF
 * @param response the HttpServletResponse to which the PDF will be written
 * @throws IOException
 */
private void sendPdf(InputStream is, String pdfName, HttpServletResponse response) throws IOException {
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + pdfName + "\"");

    ServletOutputStream outs = null;
    try {
        outs = response.getOutputStream();
        int r = 0;
        byte[] chunk = new byte[8192];
        while ((r = is.read(chunk)) != -1) {
            outs.write(chunk, 0, r);
        }
        outs.flush();
    } finally {
        IOUtils.closeQuietly(outs);
    }

}

From source file:BubbleChartDemo.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    Connection conn = null;//from   w ww . j a v  a 2 s.  c  o m
    Statement stmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsm = null;

    OutputStream out = response.getOutputStream();
    try {

        DefaultXYZDataset dataset = new DefaultXYZDataset();
        double[] x = { 2.1, 2.3, 2.3, 2.2, 2.2, 1.8, 1.8, 1.9, 2.3, 3.8 };
        double[] y = { 14.1, 11.1, 10.0, 8.8, 8.7, 8.4, 5.4, 4.1, 4.1, 25 };
        double[] z = { 2.4, 2.7, 2.7, 2.2, 2.2, 2.2, 2.1, 2.2, 1.6, 4 };
        double[][] series = new double[][] { x, y, z };
        dataset.addSeries("Series 1", series);

        JFreeChart chart = ChartFactory.createBubbleChart("Bubble Chart Demo 1", "X", "Y", dataset,
                PlotOrientation.HORIZONTAL, true, true, true);
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setForegroundAlpha(0.65f);

        XYItemRenderer renderer = plot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);

        // increase the margins to account for the fact that the auto-range
        // doesn't take into account the bubble size...
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setLowerMargin(0.15);
        domainAxis.setUpperMargin(0.15);
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setLowerMargin(0.15);
        rangeAxis.setUpperMargin(0.15);

        response.setContentType("image/png");
        int width = 800;
        int height = 600;
        ChartUtilities.writeChartAsPNG(out, chart, width, height);

    } catch (Exception e) {
        throw new ServletException(e);
    }

}