List of usage examples for javax.servlet ServletOutputStream close
public void close() throws IOException
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 w w w . j a v a2 s.c om*/ outputStream.flush(); outputStream.close(); } return null; }
From source file:com.geminimobile.web.DownloadCSVController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String msisdn = (String) request.getParameter("msisdn"); String startTime = (String) request.getParameter("starttime"); String endTime = (String) request.getParameter("endtime"); String market = (String) request.getParameter("market"); String type = (String) request.getParameter("type"); Date toDate = SearchCommand.m_sdf.parse(endTime); //String maxTimestamp = Long.toString(toDate.getTime()); Date fromDate = SearchCommand.m_sdf.parse(startTime); //String minTimestamp = Long.toString(fromDate.getTime()); CDRDataAccess cdrAccess = new CDRDataAccess(); Vector<CDREntry> cdrs = cdrAccess.getCDRsByMSISDN(msisdn, fromDate.getTime(), toDate.getTime(), market, type, 100000); // 100,000 entries max //Vector<CDREntry> cdrs = (Vector<CDREntry>) request.getSession().getAttribute("cdrResults"); StringBuffer sb = new StringBuffer(); // Write column headers sb.append("Date/Time,Market,Type,MSISDN,MO IP address,MT IP Address,Sender Domain,Recipient Domain\n"); for (CDREntry entry : cdrs) { sb.append(entry.getDisplayTimestamp() + "," + entry.getMarket() + "," + entry.getType() + "," + entry.getMsisdn() + "," + entry.getMoIPAddress() + "," + entry.getMtIPAddress() + "," + entry.getSenderDomain() + "," + entry.getRecipientDomain() + "\n"); }/*from ww w. j a va 2 s. c o m*/ String csvString = sb.toString(); response.setBufferSize(sb.length()); response.setContentLength(sb.length()); response.setContentType("text/plain; charset=UTF-8"); //response.setContentType( "text/csv" ); //response.setContentType("application/ms-excel"); //response.setHeader("Content-disposition", "attachment;filename=cdrResults.csv"); response.setHeader("Content-Disposition", "attachment; filename=" + "cdrResults.csv" + ";"); ServletOutputStream os = response.getOutputStream(); os.write(csvString.getBytes()); os.flush(); os.close(); return null; }
From source file:Bean.liquidacionBean.java
public void exportarPDF(String liqventa) throws JRException, NamingException, SQLException, IOException { dbManager conn = new dbManager(); Connection con = null;//from w w w.j a 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:net.sourceforge.fenixedu.presentationTier.Action.externalServices.ISTConnectDA.java
private void writeJSONObject(HttpServletResponse response, final JSONArray jsonObject) throws IOException { final ServletOutputStream outputStream = response.getOutputStream(); outputStream.write(jsonObject.toJSONString().getBytes()); outputStream.close(); }
From source file:com.us.servlet.AuthCode.java
protected void service(HttpServletRequest request, HttpServletResponse response) { final CodeAuth bean = AppHelper.CODE_AUTH; int width = NumberUtils.toInt(request.getParameter("width"), bean.getWidth()); int height = NumberUtils.toInt(request.getParameter("height"), bean.getHeight()); int x = width / (bean.getLength() + 1); int codeY = height - 4; int fontHeight = height - 2; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); if (StringUtil.hasText(request.getParameter("bgcolor"))) { graphics.setBackground(ColorHelper.hex2RGB(request.getParameter("bgcolor"))); }//from w w w . j a v a 2s . c o m graphics.fillRect(0, 0, width, height); graphics.setFont(new Font(bean.getFont(), Font.BOLD, fontHeight)); graphics.drawRect(0, 0, width - 1, height - 1); // if (bean.isBreakLine()) { for (int i = 0; i < 15; i++) { int x1 = RandomUtils.nextInt(width); int y1 = RandomUtils.nextInt(height); int x2 = RandomUtils.nextInt(12); int y2 = RandomUtils.nextInt(12); graphics.drawLine(x1, y1, x + x2, y1 + y2); } } char[] CHARSET_AREA = null; if (bean.getType().charAt(0) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, BIG_LETTERS); } if (bean.getType().charAt(1) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, SMALL_LETTER); } if (bean.getType().charAt(2) == '1') { CHARSET_AREA = ArrayUtils.addAll(CHARSET_AREA, NUMBERS); } StringBuilder randomCode = new StringBuilder(); for (int i = 0; i < bean.getLength(); i++) { String rand = String.valueOf(CHARSET_AREA[RandomUtils.nextInt(CHARSET_AREA.length)]); graphics.setColor(ColorHelper.color(RandomUtils.nextInt(255), RandomUtils.nextInt(255), RandomUtils.nextInt(255))); graphics.drawString(rand, (i + 1) * x, codeY); randomCode.append(rand); } HttpSession session = request.getSession(); session.setAttribute(bean.getSessionKey(), randomCode.toString()); // ? response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/png"); try { // Servlet? ServletOutputStream sos = response.getOutputStream(); ImageIO.write(image, "png", sos); sos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.knurt.fam.template.controller.letter.LetterGeneratorShowLetter.java
private void processIntern(HttpServletResponse response, PostMethod post, String customid) { // forward response got // force "save as" in browser String downloadFilename = this.df.format(new Date()) + "-" + customid + ".pdf"; response.setHeader("Content-Disposition", "attachment; filename=" + downloadFilename); // it is a pdf response.setContentType("application/pdf"); try {/*from www .j a v a2 s . com*/ ServletOutputStream ouputStream = response.getOutputStream(); ouputStream.write(post.getResponseBody()); ouputStream.flush(); ouputStream.close(); } catch (IOException e) { FamLog.exception(e, 201106131408l); } }
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);/*from w w w .jav a 2 s . 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:com.octo.captcha.module.acegi.JCaptchaSoundController.java
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsWav = null; ByteArrayOutputStream wavOutputStream = 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(); AudioInputStream challenge = soundCaptchaService.getSoundChallengeForID(captchaId, httpServletRequest.getLocale()); // a jpeg encoder AudioInputStream stream = (AudioInputStream) challenge; // call the ImageCaptchaService method to retrieve a captcha AudioSystem.write(stream, AudioFileFormat.Type.WAVE, wavOutputStream); captchaChallengeAsWav = wavOutputStream.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("audio/x-wav"); ServletOutputStream responseOutputStream = response.getOutputStream(); responseOutputStream.write(captchaChallengeAsWav); responseOutputStream.flush();//from w w w. j a v a 2s . c o m responseOutputStream.close(); return null; }
From source file:org.chimi.s4s.controller.FileDownloadController.java
private void sendFile(boolean imageInline, FileSource source, HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType(source.getMimeType()); cacheStrategy.setCacheOption(source, response); response.setHeader("Content-Disposition", (imageInline ? "inline" : "attachment") + "; filename=\"" + getHeaderFileName(source.getFileName(), request) + "\";"); response.setContentLength((int) source.getLength()); ServletOutputStream out = response.getOutputStream(); source.write(out);//from w w w .j a v a 2 s . c om out.flush(); out.close(); }
From source file:com.tapas.evidence.fe.controller.CaptchaController.java
@RequestMapping("/captcha.jpg") public void showForm(HttpServletRequest request, HttpServletResponse response) throws Exception { byte[] captchaChallengeAsJpeg = null; // the output stream to render the captcha image as jpeg into ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream(); try {//from w ww. j av a 2s . c om // 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 = request.getSession().getId(); BufferedImage challenge = captchaService.getImageChallengeForID(captchaId, request.getLocale()); ImageIO.write(challenge, CAPTCHA_IMAGE_FORMAT, jpegOutputStream); } catch (IllegalArgumentException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch (CaptchaServiceException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } captchaChallengeAsJpeg = jpegOutputStream.toByteArray(); // flush it in the response response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/" + CAPTCHA_IMAGE_FORMAT); ServletOutputStream responseOutputStream = response.getOutputStream(); responseOutputStream.write(captchaChallengeAsJpeg); responseOutputStream.flush(); responseOutputStream.close(); }