List of usage examples for javax.servlet.http HttpServletResponse setContentLength
public void setContentLength(int len);
From source file:com.ms.app.web.commons.pagecache.PageCacheManager.java
/** * ?//from ww w .j a v a2 s . co m * * @param request * @param response * @param pageInfo * @throws IOException */ protected void writeContent(final HttpServletRequest request, final HttpServletResponse response, final PageInfo pageInfo) throws IOException { byte[] body = pageInfo.getBody(); response.setContentLength(body.length); response.getOutputStream().write(body); }
From source file:fedora.localservices.fop.FOPServlet.java
private void sendPDF(byte[] content, HttpServletResponse response) throws IOException { //Send the result back to the client response.setContentType("application/pdf"); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush();/* w w w .j a v a 2s . co m*/ }
From source file:com.azavea.fop.pdf.Foplet.java
/** * Send the PDF content in the response. * * @param content A byte array of PDF content. * @param response An HttpServletResponse. * @throws IOException/*from w ww. j a va 2s . co m*/ */ private void sendPDF(byte[] content, HttpServletResponse response) throws IOException { //Send the result back to the client response.setContentType("application/pdf"); response.setContentLength(content.length); response.getOutputStream().write(content); response.getOutputStream().flush(); }
From source file:mx.edu.um.mateo.general.web.ImagenController.java
@RequestMapping("/mostrar/{id}") public String mostrar(HttpServletRequest request, HttpServletResponse response, @PathVariable Long id) { log.debug("Mostrando imagen {}", id); Imagen imagen = (Imagen) currentSession().get(Imagen.class, id); if (imagen != null) { response.setContentType(imagen.getTipoContenido()); response.setContentLength(imagen.getTamano().intValue()); try {/*w ww .j a v a 2s .c o m*/ response.getOutputStream().write(imagen.getArchivo()); } catch (IOException e) { log.error("No se pudo escribir el archivo", e); throw new RuntimeException("No se pudo escribir el archivo en el outputstream"); } } else { try { response.sendRedirect(request.getContextPath() + "/images/sin-foto.jpg"); } catch (IOException e) { log.error("No se pudo obtener la imagen", e); } } return null; }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsNtlmProcessingFilterEntryPoint.java
/** * {@inheritDoc}//www . ja va2 s. c o m * @see org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint#commence( * javax.servlet.ServletRequest, javax.servlet.ServletResponse, * org.springframework.security.AuthenticationException) */ @Override public void commence(final ServletRequest req, final ServletResponse res, final AuthenticationException authException) throws IOException, ServletException { // start authentication, if necessary and forceIdentification in NtlmProcessingFilter is false if (!(authException instanceof NtlmBaseException || authException instanceof BadCredentialsException)) { HttpServletRequest request = (HttpServletRequest) req; request.getSession().setAttribute(STATE_ATTR, BEGIN); HttpServletResponse response = (HttpServletResponse) res; response.setHeader("WWW-Authenticate", new NtlmBeginHandshakeException().getMessage()); response.setHeader("Connection", "Keep-Alive"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setContentLength(0); response.flushBuffer(); } else { super.commence(req, res, authException); } }
From source file:com.github.jrialland.ajpclient.AbstractTomcatTest.java
@SuppressWarnings("serial") protected void addStaticResource(final String mapping, final Path file) { if (!Files.isRegularFile(file)) { final FileNotFoundException fnf = new FileNotFoundException(file.toString()); fnf.fillInStackTrace();//from w ww .j av a2s .c om throw new IllegalArgumentException(fnf); } String md5; try { final InputStream is = file.toUri().toURL().openStream(); md5 = computeMd5(is); is.close(); } catch (final Exception e) { throw new RuntimeException(e); } final String fMd5 = md5; addServlet(mapping, new HttpServlet() { @Override protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { resp.setContentLength((int) Files.size(file)); resp.setHeader("Content-MD5", fMd5); final String mime = Files.probeContentType(file); if (mime != null) { resp.setContentType(mime); } final OutputStream out = resp.getOutputStream(); Files.copy(file, out); out.flush(); } }); }
From source file:es.galvarez.rest.config.RestAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { response.addHeader("Access-Control-Allow-Origin", "null"); response.addHeader("WWW-Authenticate", "RestBasic realm=\"" + getRealmName() + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setContentLength(0); }
From source file:org.openmrs.module.clinicalsummary.web.controller.printer.PrintSummariesController.java
/** * Attach the file to the servlet response body * * @param response/*from ww w . j av a2s .c o m*/ * the response * @param file * the file * * @throws Exception */ private void attachAndPurgeFile(HttpServletResponse response, File file) throws Exception { response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); response.setContentType(MimeConstants.MIME_PDF); response.setContentLength((int) file.length()); FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); if (!file.delete()) { log.info("Deleting temporary file failed!"); } }
From source file:ar.com.fdvs.dj.output.FileReportWriter.java
public void writeTo(final HttpServletResponse _response) throws IOException, JRException { LOGGER.info("entering FileReportWriter.writeTo()"); final File file = File.createTempFile("djreport", ".tmp"); try {//from w ww. java 2 s . c o m exporter.setParameter(JRExporterParameter.OUTPUT_FILE, file); exporter.exportReport(); _response.setContentLength((int) file.length()); copyStreams(new FileInputStream(file), _response.getOutputStream()); } finally { LOGGER.info("deleting " + file.getAbsolutePath()); file.delete(); } }