List of usage examples for javax.servlet.http HttpServletResponse setContentLength
public void setContentLength(int len);
From source file:mx.gob.cfe.documentos.web.CircularController.java
private void generaReporte(String tipo, List<Documento> documentos, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(documentos); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=circular.pdf"); break;// w w w. j a va 2 s . c o m } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:mx.gob.cfe.documentos.web.MemoInterController.java
private void generaReporte(String tipo, List<Documento> documentos, HttpServletResponse response) throws JRException, IOException { log.debug("Generando reporte {}", tipo); byte[] archivo = null; switch (tipo) { case "PDF": archivo = generaPdf(documentos); response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=memoInter.pdf"); break;// w w w. j a va 2s.co m } if (archivo != null) { response.setContentLength(archivo.length); try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { bos.write(archivo); bos.flush(); } } }
From source file:alfio.controller.api.admin.ResourceController.java
@RequestMapping(value = "/resource-event/{organizationId}/{eventId}/{name:.*}", method = RequestMethod.GET) public void outputContent(@PathVariable("organizationId") int organizationId, @PathVariable("eventId") int eventId, @PathVariable("name") String name, Principal principal, HttpServletResponse response) throws IOException { checkAccess(organizationId, eventId, principal); UploadedResource metadata = uploadedResourceManager.get(organizationId, eventId, name); try (OutputStream os = response.getOutputStream()) { response.setContentType(metadata.getContentType()); response.setContentLength(metadata.getContentSize()); uploadedResourceManager.outputResource(organizationId, eventId, name, os); }// w w w.j a va 2s .c om }
From source file:net.sourceforge.fenixedu.presentationTier.Action.candidate.degree.DegreeCandidacyManagementDispatchAction.java
public ActionForward showSummaryFile(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { CandidacySummaryFile file = getCandidacy(request).getSummaryFile(); response.reset();/* www. j av a 2 s. c o m*/ try { response.getOutputStream().write(file.getContents()); response.setContentLength(file.getContents().length); response.setContentType("application/pdf"); response.flushBuffer(); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
From source file:org.gallery.web.controller.FileController.java
@RequestMapping(value = "/downloadfile/{id}", params = { "attachment" }, method = RequestMethod.GET) public void download(HttpServletResponse response, @PathVariable("id") Long id, @RequestParam("attachment") boolean attachment) { log.info("downloadfile called..."); DataFileEntity entity = dataFileDao.getById(id); if (entity == null) { return;/*from w w w . j a v a2 s . c om*/ } else { String realPath = fileUploadDirectory + File.separatorChar + entity.getKey(); File file = new File(realPath); response.setContentType(entity.getContentType()); response.setContentLength(entity.getSize().intValue()); if (attachment) try { response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(entity.getName(), "UTF-8")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block log.error("Could not encode " + entity.getName(), e1); } try { InputStream is = new FileInputStream(file); IOUtils.copy(is, response.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block log.error("Could not download: " + entity.toString(), e); } } }
From source file:org.onlab.stc.MonitorWebSocketServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getRequestURI(); uri = uri.length() <= 1 ? "/index.html" : uri; InputStream resource = getClass().getResourceAsStream(uri); if (resource == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else {// ww w . ja v a2 s . c o m byte[] entity = ByteStreams.toByteArray(resource); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(contentType(uri).toString()); resp.setContentLength(entity.length); resp.getOutputStream().write(entity); } }
From source file:com.benfante.minimark.controllers.ResultsController.java
@RequestMapping public void pdf(@RequestParam("id") Long id, HttpServletRequest req, HttpServletResponse res, Locale locale) { AssessmentFilling assessmentInfo = assessmentFillingDao.get(id); userProfileBo.checkEditAuthorization(assessmentInfo.getAssessment()); OutputStream out = null;/*w w w. j a va 2s . c om*/ try { byte[] pdfBytes = assessmentPdfBuilder.buildPdf(assessmentInfo, Utilities.getBaseUrl(req), locale); out = res.getOutputStream(); res.setContentType("application/pdf"); res.setContentLength(pdfBytes.length); res.setHeader("Content-Disposition", " attachment; filename=\"" + assessmentInfo.getLastName() + "_" + assessmentInfo.getFirstName() + ".pdf\""); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "public"); out.write(pdfBytes); out.flush(); } catch (Exception ex) { logger.error("Can't build PDF file for " + assessmentInfo.getIdentifier() + " " + assessmentInfo.getFirstName() + " " + assessmentInfo.getLastName(), ex); } finally { if (out != null) { try { out.close(); } catch (IOException ioe) { } } } }
From source file:com.janrain.backplane.server.Backplane1Controller.java
@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.HEAD }) public ModelAndView greetings(HttpServletRequest request, HttpServletResponse response) { if (RequestMethod.HEAD.toString().equals(request.getMethod())) { response.setContentLength(0);/*from w ww .j a va 2s . c o m*/ } return new ModelAndView("welcome"); }
From source file:werecloud.api.view.JSONView.java
@Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { ServletOutputStream out = response.getOutputStream(); if (model.containsKey("model")) { ObjectMapper mapper = new ObjectMapper(); //use ISO-8601 dates instead of timestamp mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, outputNulls); ByteArrayOutputStream bos = new ByteArrayOutputStream(); mapper.writeValue(bos, model.get("model")); response.setContentLength(bos.size()); response.setContentType("application/json"); out.write(bos.toByteArray());//from w ww . ja v a 2s . c o m return; } throw new Exception("Could not find model."); }