List of usage examples for javax.servlet.http HttpServletResponse setContentLength
public void setContentLength(int len);
From source file:org.shimlib.web.servlet.view.filedownload.FileDownloadView.java
@Override protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException { response.setContentLength(baos.size()); // Flush byte array to servlet output stream. ServletOutputStream out = response.getOutputStream(); baos.writeTo(out);//from w w w. j av a 2 s.com out.flush(); }
From source file:com.netspective.sparx.navigate.client.AuthenticatedUserDelegatedServiceHandler.java
public void handleClientServiceRequest(NavigationContext nc, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ClientServiceRequestHandlerException { httpServletResponse.setContentLength(0); AuthenticatedUser user = nc.getAuthenticatedUser(); if (user == null) log.error(//from w w w.j a v a2s .co m "Attempting to call AuthenticatedUserDelegatedServiceHandler.handleClientServiceRequest but there is no authenticated user."); else if (user instanceof ClientServiceRequestHandler) ((ClientServiceRequestHandler) user).handleClientServiceRequest(nc, httpServletRequest, httpServletResponse); else log.error( "Attempting to call AuthenticatedUserDelegatedServiceHandler.handleClientServiceRequest but AuthenticatedUser does not implement " + ClientServiceRequestHandler.class + " interface"); }
From source file:cn.vlabs.clb.server.ui.frameservice.pdf.handler.GetPdfContentHandler.java
private void writePdfContentToResponse(GridFSDBFile dbfile, HttpServletRequest request, HttpServletResponse response) { OutputStream os = null;/*w w w . j a v a2s.c om*/ try { response.setContentLength((int) dbfile.getLength()); response.setContentType("application/x-download"); String filename = dbfile.getFilename(); String headerValue = ResponseHeaderUtils.buildResponseHeader(request, filename, true); response.setHeader("Content-Disposition", headerValue); response.setHeader("Content-Length", dbfile.getLength() + ""); os = response.getOutputStream(); dbfile.writeTo(os); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (os != null) { IOUtils.closeQuietly(os); } } }
From source file:be.solidx.hot.test.nio.http.EchoPOSTServlet.java
protected void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(req.getContentType()); resp.setContentLength(req.getContentLength()); String body = IOUtils.toString(req.getInputStream()); System.out.println(body);/*from ww w . j a v a 2 s.co m*/ resp.getWriter().write(body); }
From source file:com.nominanuda.springmvc.StaticViewResolver.java
public View resolveViewName(String viewName, Locale locale) throws Exception { URL url = resolve(viewName, locale); if (url == null) { return null; } else {/*from w ww. java2s . c o m*/ if (cache) { View cv = findCachedView(url); if (cv != null) { return cv; } } final byte[] barr = io.readAndClose(url.openStream()); View v = new View() { public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentLength(barr.length); response.setContentType(contentType); OutputStream os = response.getOutputStream(); os.write(barr); os.flush(); } public String getContentType() { return contentType; } }; if (cache) { storeCachedView(url, v); } return v; } }
From source file:fr.putnami.pwt.plugin.ajaxbot.controller.SiteMapController.java
@RequestMapping(value = "/sitemap.txt", method = RequestMethod.GET) public void welcomePage(HttpServletResponse response) { try {/*from ww w . j a va 2s . com*/ InputStream is = new FileInputStream(sitemap); response.setContentType("text/plain"); response.setContentLength((int) sitemap.length()); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { throw new RuntimeException("IOError writing file to output stream", ex); } }
From source file:com.vigglet.oei.service.GetServicePdfServlet.java
@Override protected void downloadPdf(HttpServletRequest req, HttpServletResponse resp, User user, int modelId) throws Exception { File file = new ServicePdf(ServiceUtil.getInstance().findById(modelId), user).createServiceReport(); resp.setContentLength((int) file.length()); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, resp.getOutputStream()); IOUtils.closeQuietly(fis);//from w ww .j a v a 2s .c om }
From source file:com.cami.web.controller.uploadController.java
@RequestMapping(value = "/get/{value}", method = RequestMethod.GET) public void get(HttpServletResponse response, @PathVariable String value) { try {/*ww w .j a v a2s . c o m*/ response.setContentType(ufile.type); response.setContentLength(ufile.length); FileCopyUtils.copy(ufile.bytes, response.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.surevine.alfresco.audit.integration.ResponseModifiableMockFilterChain.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response) { super.doFilter(request, response); try {//from w w w . j a v a2s . c om HttpServletResponse httpServletResponse = (HttpServletResponse) response; httpServletResponse.getOutputStream().write(content.getBytes()); httpServletResponse.setContentLength(content.length()); httpServletResponse.setStatus(this.status); httpServletResponse.flushBuffer(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.vigglet.oei.vehicle.GetVehiclePdfServlet.java
@Override protected void downloadPdf(HttpServletRequest req, HttpServletResponse resp, User user, final int modelId) throws Exception { File file = new ServicereportPdf(VehicleUtil.getInstance().findById(modelId), user).createServiceReport(); resp.setContentLength((int) file.length()); FileInputStream fis = new FileInputStream(file); IOUtils.copy(fis, resp.getOutputStream()); IOUtils.closeQuietly(fis);//ww w .j a v a 2s.com }