Example usage for javax.servlet ServletOutputStream flush

List of usage examples for javax.servlet ServletOutputStream flush

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:org.fenixedu.academic.ui.struts.action.internationalRelatOffice.candidacy.erasmus.ErasmusIndividualCandidacyProcessDA.java

public ActionForward retrieveLearningAgreement(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    MobilityIndividualApplicationProcess process = getProcess(request);

    final LearningAgreementDocument document = new LearningAgreementDocument(process);
    byte[] data = ReportsUtils.generateReport(document).getData();

    response.setContentLength(data.length);
    response.setContentType("application/pdf");
    response.addHeader("Content-Disposition", "attachment; filename=" + document.getReportFileName() + ".pdf");

    final ServletOutputStream writer = response.getOutputStream();
    writer.write(data);/*from  www .  j a v  a2s  .c o  m*/
    writer.flush();
    writer.close();

    response.flushBuffer();
    return mapping.findForward("");
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.internationalRelatOffice.candidacy.erasmus.ErasmusIndividualCandidacyProcessDA.java

public ActionForward retrieveLearningAgreement(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    MobilityIndividualApplicationProcess process = getProcess(request);

    final LearningAgreementDocument document = new LearningAgreementDocument(process);
    byte[] data = ReportsUtils.exportMultipleToPdfAsByteArray(document);

    response.setContentLength(data.length);
    response.setContentType("application/pdf");
    response.addHeader("Content-Disposition", "attachment; filename=" + document.getReportFileName() + ".pdf");

    final ServletOutputStream writer = response.getOutputStream();
    writer.write(data);/* w  w  w.ja va 2 s.c  om*/
    writer.flush();
    writer.close();

    response.flushBuffer();
    return mapping.findForward("");
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.lists.StudentsListByCurricularCourseDA.java

public ActionForward doExportInfoToExcel(ActionMapping mapping, ActionForm actionForm,
        HttpServletRequest request, HttpServletResponse response, Boolean detailed)
        throws FenixServiceException {

    final CurricularCourse curricularCourse = getDomainObject(request, "curricularCourseCode");
    final Integer semester = getIntegerFromRequest(request, "semester");
    final ExecutionYear executionYear = ExecutionYear
            .readExecutionYearByName((String) getFromRequest(request, "curricularYear"));
    final String year = (String) getFromRequest(request, "year");

    try {//  w  w w  . j  a va2  s .c  o  m
        String filename = getResourceMessage("label.students") + "_" + curricularCourse.getName() + "_("
                + curricularCourse.getDegreeCurricularPlan().getName() + ")_" + executionYear.getYear();

        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition",
                "attachment; filename=" + filename.replace(" ", "_") + ".xls");
        ServletOutputStream writer = response.getOutputStream();

        exportToXls(searchStudentByCriteria(executionYear, curricularCourse, semester), writer, executionYear,
                curricularCourse, year, semester.toString(), detailed);
        writer.flush();
        response.flushBuffer();

    } catch (IOException e) {
        throw new FenixServiceException();
    }

    return null;

}

From source file:com.openkm.servlet.admin.StampServlet.java

/**
 * View image stamp/*w  ww .  j av  a2  s .c o m*/
 */
private void imageView(Session session, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, DatabaseException {
    log.debug("imageView({}, {}, {})", new Object[] { session, request, response });
    int siId = WebUtils.getInt(request, "si_id");
    StampImage si = StampImageDAO.findByPk(siId);
    response.setContentType(si.getImageMime());
    ServletOutputStream sos = response.getOutputStream();
    sos.write(SecureStore.b64Decode(si.getImageContent()));
    sos.flush();
    sos.close();
    log.debug("imageView: void");
}

From source file:com.jd.survey.web.settings.DataSetController.java

/**
 * exports a sample dataset items a comma delimited file
 * @param dataSetId/* w  ww.j  a va 2 s .c  om*/
 * @param principal
 * @param response
 */

@RequestMapping(value = "/example", produces = "text/html")
public void getExampleCsvFile(Principal principal, HttpServletResponse response) {
    try {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(messageSource
                .getMessage(VALUE_FIELD_NAME_MESSAGE, null, LocaleContextHolder.getLocale()).replace(",", ""));
        stringBuilder.append(",");
        stringBuilder.append(messageSource
                .getMessage(TEXT_FIELD_NAME_MESSAGE, null, LocaleContextHolder.getLocale()).replace(",", ""));
        stringBuilder.append("\n");
        stringBuilder.append("B,Boston\n");
        stringBuilder.append("N,New York\n");
        //response.setContentType("text/html; charset=utf-8");
        response.setContentType("application/octet-stream");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache,must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Content-Disposition", "inline;filename=datasetExample.csv");
        ServletOutputStream servletOutputStream = response.getOutputStream();
        servletOutputStream.write(stringBuilder.toString().getBytes("UTF-8"));
        servletOutputStream.flush();

    }

    catch (Exception e) {
        log.error(e.getMessage(), e);
        throw (new RuntimeException(e));
    }

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.scientificCouncil.credits.MasterDegreeCreditsManagementDispatchAction.java

public ActionForward exportToExcel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse response) throws FenixServiceException {

    ExecutionDegree executionDegree = getExecutionDegreeFromParameter(request);
    List<MasterDegreeCreditsDTO> listing = getListing(executionDegree);
    if (!listing.isEmpty()) {
        Collections.sort(listing, new BeanComparator("curricularCourse.name"));
    }/*  www . j ava 2 s .co  m*/

    try {
        String filename = getFileName(executionDegree);
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-disposition", "attachment; filename=" + filename + ".xls");

        ServletOutputStream writer = response.getOutputStream();
        exportToXls(executionDegree, listing, writer);

        writer.flush();
        response.flushBuffer();

    } catch (IOException e) {
        throw new FenixServiceException();
    }
    return null;
}

From source file:org.inbio.ait.web.ajax.controller.IndicatorsTreeController.java

private ModelAndView writeReponse(HttpServletRequest request, HttpServletResponse response,
        List<AutocompleteNode> acnList) throws Exception {

    response.setCharacterEncoding("ISO-8859-1");
    response.setContentType("text/xml");
    // Binary output
    ServletOutputStream out = response.getOutputStream();

    if (acnList != null) {
        StringBuilder result = new StringBuilder();
        result.append("<?xml version='1.0' encoding='ISO-8859-1'?><response>");
        for (AutocompleteNode sp : acnList) {
            result.append("<node><id>" + sp.getItemId() + "</id>");
            result.append("<name>" + sp.getItemName() + "</name></node>");
        }//from   ww w . ja  va2 s  .c  o  m
        result.append("</response>");
        out.println(result.toString());
    }

    out.flush();
    out.close();

    return null;
}

From source file:com.google.appengine.tools.mapreduce.MapReduceServletTest.java

public void testStaticResources_status() throws Exception {
    HttpServletResponse resp = createMock(HttpServletResponse.class);
    resp.setContentType("text/html");
    resp.setHeader("Cache-Control", "public; max-age=300");
    ServletOutputStream sos = createMock(ServletOutputStream.class);
    expect(resp.getOutputStream()).andReturn(sos);
    sos.write((byte[]) EasyMock.anyObject(), EasyMock.eq(0), EasyMock.anyInt());
    EasyMock.expectLastCall().atLeastOnce();
    sos.flush();
    EasyMock.expectLastCall().anyTimes();
    replay(resp, sos);/*from  ww  w  . j a  v  a  2s.  c om*/
    servlet.handleStaticResources("status", resp);
    verify(resp, sos);
}

From source file:com.google.appengine.tools.mapreduce.MapReduceServletTest.java

public void testStaticResources_jQuery() throws Exception {
    HttpServletResponse resp = createMock(HttpServletResponse.class);
    resp.setContentType("text/javascript");
    resp.setHeader("Cache-Control", "public; max-age=300");
    ServletOutputStream sos = createMock(ServletOutputStream.class);
    expect(resp.getOutputStream()).andReturn(sos);
    sos.write((byte[]) EasyMock.anyObject(), EasyMock.eq(0), EasyMock.anyInt());
    EasyMock.expectLastCall().atLeastOnce();
    sos.flush();
    EasyMock.expectLastCall().anyTimes();
    replay(resp, sos);/*from w ww .  ja  va 2  s  .c o  m*/
    servlet.handleStaticResources("jquery.js", resp);
    verify(resp, sos);
}

From source file:com.edgenius.wiki.webapp.action.RSSFeedAction.java

public String execute() {
    Space space;/*from www .j a v  a2 s  . c o m*/
    if (NumberUtils.toInt(suid, -1) != -1) {
        int spaceUid = NumberUtils.toInt(suid);
        space = spaceService.getSpace(spaceUid);
    } else {
        space = spaceService.getSpaceByUname(s);
    }
    if (space == null)
        return ERROR;

    User user = WikiUtil.getUser();
    String out = null;
    try {
        out = rssService.outputFeed(space.getUid(), space.getUnixName(), user);
    } catch (FeedException e) {
        log.error("Read feed error ", e);
    }
    try {
        ServletOutputStream writer = getResponse().getOutputStream();
        if (out != null) {
            //out must XML format
            getResponse().setContentType("text/xml");
            writer.write(out.getBytes(Constants.UTF8));
        } else {
            //feed does not exist for some reason, try to re-generate
            writer.write(("Please wait a while for RSS feed generating in system. Refresh later.")
                    .getBytes(Constants.UTF8));
            writer.flush();
            rssService.createFeed(space.getUnixName());
        }
    } catch (IOException e) {
        log.error("unable write out feed", e);
        return ERROR;
    }
    return null;
}