List of usage examples for javax.servlet ServletOutputStream flush
public void flush() throws IOException
From source file:com.zilverline.MockHandler.java
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { invariant();// www. j ava2 s . c o m ServletOutputStream outputStream = response.getOutputStream(); IOUtils.copy(responseResource.getInputStream(), outputStream); outputStream.flush(); }
From source file:it.jugpadova.controllers.JCaptchaController.java
@RequestMapping public void image(HttpServletRequest req, HttpServletResponse res) throws IOException { byte[] captchaChallengeAsJpeg = null; // the output stream to render the captcha image as jpeg into ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); // get the session id that will identify the generated captcha. //the same id must be used to validate the res, the session id is a good candidate! String captchaId = req.getSession().getId(); // call the ImageCaptchaService getChallenge method BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, req.getLocale()); // a jpeg encoder JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream); jpegEncoder.encode(challenge);//from w ww. j ava2 s . c om captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // flush it in the res res.setHeader("Cache-Control", "no-store"); res.setHeader("Pragma", "no-cache"); res.setDateHeader("Expires", 0); res.setContentType("image/jpeg"); ServletOutputStream resOutputStream = res.getOutputStream(); resOutputStream.write(captchaChallengeAsJpeg); resOutputStream.flush(); resOutputStream.close(); }
From source file:org.fenixedu.parking.ui.Action.externalServices.ExportParkingData.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { final String password = request.getParameter("password"); final String username = request.getParameter("username"); checkPermissions(username, password); ParkingDataReportFile parkingDataReportFile = getLastParkingDataReportJob(); if (parkingDataReportFile != null && parkingDataReportFile.getFile() != null) { final byte[] data = parkingDataReportFile.getFile().getContent(); response.setContentLength(data.length); response.setContentType("application/vnd.ms-access"); response.setHeader("Content-disposition", "attachment; filename=" + parkingDataReportFile.getFilename()); final ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(data);/*from www. j ava2 s.co m*/ outputStream.flush(); outputStream.close(); } return null; }
From source file:de.fau.amos4.web.PrintDataController.java
@RequestMapping("/employee/download/text") public ModelAndView EmployeeDownloadText(HttpServletResponse response, @RequestParam(value = "id", required = true) long employeeId) throws IOException { // Use the service to get the Employee in the LODAS format final String employeeAsLodas = employeeService.getLodasRepresentation(employeeId); if (employeeAsLodas == null) { return new ModelAndView("redirect:/client/dashboard"); }//from ww w. ja v a 2 s . c o m // We want to have a txt file download response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment;filename=employee_as_lodas.txt"); response.setCharacterEncoding("UTF-8"); // Write the data out ServletOutputStream out = response.getOutputStream(); out.write(employeeAsLodas.getBytes()); out.flush(); out.close(); return null; }
From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.PosterImageServlet.java
/** * Returns poster image/*from w w w.ja va 2s . c om*/ * * @param request the request * @param response the response * @throws ServletException the servlet exception * @throws IOException Signals that an I/O exception has occurred. */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String sIdProduct = request.getParameter(PARAMETER_PRODUCT_ID); if (StringUtils.isNotEmpty(sIdProduct)) { Integer idProduct = Integer.parseInt(sIdProduct); boolean isThumbnail = (request.getParameter(PARAMETER_TB) != null) && request.getParameter(PARAMETER_TB).equals(String.valueOf(true)); byte[] bImage; if (isThumbnail) { bImage = _productService.getTbImage(idProduct); } else { bImage = _productService.getImage(idProduct); } response.setContentLength(bImage.length); response.setContentType(CONTENT_TYPE_IMAGE_JPEG); ServletOutputStream os = response.getOutputStream(); IOUtils.write(bImage, os); os.flush(); os.close(); } else { LOGGER.error(ERROR_MESSAGE); } }
From source file:Bean.liquidacionBean.java
public void exportarPDF(String liqventa) throws JRException, NamingException, SQLException, IOException { dbManager conn = new dbManager(); Connection con = null;/* w w w. ja v a 2 s . com*/ con = conn.getConnection(); Map<String, Object> parametros = new HashMap<String, Object>(); if (StringUtils.isNotBlank(liqventa)) { parametros.put("liqventa", liqventa); System.out.println(liqventa); File jasper = new File("D:/reporte/liquidacion.jasper"); JasperPrint jasperPrint = JasperFillManager.fillReport(jasper.getPath(), parametros, con); HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.addHeader("Content-disposition", "attachment; filename=Liquidacin" + liqventa + ".pdf"); ServletOutputStream stream = response.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, stream); stream.flush(); stream.close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Error", "Generar Crdito.")); } }
From source file:egovframework.rte.fdl.excel.util.AbstractPOIExcelView.java
/** * Renders the Excel view, given the specified model. *//* w w w . j a v a 2 s.co m*/ @Override protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { XSSFWorkbook workbook = new XSSFWorkbook(); logger.debug("Created Excel Workbook from scratch"); /*if (workbook instanceof XSSFWorkbook) { setContentType(CONTENT_TYPE_XLSX); } else { setContentType(CONTENT_TYPE_XLS); }*/ setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); buildExcelDocument(model, workbook, request, response); // Set the content type. response.setContentType(getContentType()); // Flush byte array to servlet output stream. ServletOutputStream out = response.getOutputStream(); out.flush(); workbook.write(out); out.flush(); // Don't close the stream - we didn't open it, so let the container // handle it. // http://stackoverflow.com/questions/1829784/should-i-close-the-servlet-outputstream }
From source file:org.jahia.bin.WorkflowImageController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String wfKey = request.getParameter("workflowKey"); String basePath = "/" + StringUtils.substringBefore(wfKey, ":").replaceAll("\\.", "/") + "/"; wfKey = StringUtils.substringAfter(wfKey, ":"); WorklowTypeRegistration workflowRegistration = workflowService.getWorkflowRegistration(wfKey); JahiaTemplatesPackage module = workflowRegistration.getModule(); String language = request.getParameter("language"); Resource resource = module.getResource(basePath + wfKey + "_" + language + ".png"); if (resource == null) { resource = module.getResource(basePath + wfKey + ".png"); }/*w w w.ja va 2 s. com*/ if (resource != null) { response.setContentType("image/png"); ServletOutputStream out = response.getOutputStream(); IOUtils.copy(resource.getInputStream(), out); out.flush(); } response.setStatus(HttpServletResponse.SC_OK); return null; }
From source file:com.octo.captcha.module.acegi.JCaptchaImageController.java
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); //get the session id that will identify the generated captcha. //the same id must be used to validate the response, the session id is a good candidate! String captchaId = httpServletRequest.getSession().getId(); BufferedImage challenge = imageCaptchaService.getImageChallengeForID(captchaId, httpServletRequest.getLocale()); JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream); jpegEncoder.encode(challenge);/* ww w . jav a2s . c o m*/ captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // configure cache directives response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); //flush content in the response response.setContentType("image/jpeg"); ServletOutputStream responseOutputStream = response.getOutputStream(); responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush(); responseOutputStream.close(); return null; }
From source file:org.centralperf.helper.view.AbstractPOIExcelView.java
@Override protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Workbook workbook = null;/* w ww.j a v a 2 s .c o m*/ if (url != null) { workbook = getTemplateSource(url, request); } else { workbook = createWorkbook(); } if (workbook instanceof XSSFWorkbook) { setContentType(CONTENT_TYPE_XLSX); } else { setContentType(CONTENT_TYPE_XLS); } buildExcelDocument(model, workbook, request, response); // Set the content type. response.setContentType(getContentType()); // Flush byte array to servlet output stream. ServletOutputStream out = response.getOutputStream(); out.flush(); // Have to catch exception because of thise bug : https://issues.apache.org/bugzilla/show_bug.cgi?id=49940 try { workbook.write(out); } catch (org.apache.xmlbeans.impl.values.XmlValueDisconnectedException disconnectedException) { // Do nothing... In fact, it's only a bug... } out.flush(); // Don't close the stream - we didn't open it, so let the container // handle it. // http://stackoverflow.com/questions/1829784/should-i-close-the-servlet-outputstream }