List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.Default.java
public void handleOptions(HttpServletRequest request, HttpServletResponse response) throws IOException { // Handle OPTIONS request for entire server // 9.2//from w ww . j a va 2s . c o m response.setIntHeader(HttpFields.__ContentLength, 0); response.setHeader(HttpFields.__Allow, _AllowString); response.flushBuffer(); }
From source file:de.undercouch.gradle.tasks.download.ETagTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler lastModifiedHandler = new ContextHandler("/" + ETAG) { @Override//from w w w . j a va 2 s . c o m public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { String ifNoneMatch = request.getHeader("If-None-Match"); if (etag != null && etag.equals(ifNoneMatch)) { response.setStatus(304); response.flushBuffer(); } else { response.setStatus(200); if (etag != null) { response.setHeader("ETag", etag); } PrintWriter rw = response.getWriter(); rw.write("etag: " + etag); rw.close(); } } }; return new Handler[] { lastModifiedHandler }; }
From source file:nl.strohalm.cyclos.servlets.ImageByNameServlet.java
/** * Write the image file to the response/*from w w w .ja v a 2 s .c o m*/ */ private void write(final HttpServletRequest request, final HttpServletResponse response, final File file, final ImageType type) throws IOException { final long ifModifiedSince = request.getDateHeader("If-Modified-Since"); if (ifModifiedSince > 0 && file.lastModified() <= ifModifiedSince) { // The contents have not changed response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } // The contents are modified, or not in browser's cache. Render it if (type != null) { response.setContentType(type.getContentType()); } responseHelper.writeFile(response, file); response.flushBuffer(); }
From source file:org.fao.geonet.api.userfeedback.UserFeedbackAPI.java
/** * Prints the output message.//from ww w . j av a2s.co m * * @param response the response * @param code the code * @param message the message * @throws IOException Signals that an I/O exception has occurred. */ private void printOutputMessage(final HttpServletResponse response, final HttpStatus code, final String message) throws IOException { response.setStatus(code.value()); final PrintWriter out = response.getWriter(); response.setContentType("text/html"); out.println(message); response.flushBuffer(); }
From source file:it.polimi.diceH2020.launcher.controller.rest.DownloadsController.java
private void respondWithZipFile(@NotNull Map<String, String> files, @NotNull HttpServletResponse response) { File zipPath = null;/*from w w w. j a v a2s . co m*/ try { zipPath = fileUtility.createTempZip(files); } catch (IOException e) { logger.error("Problem creating zip file", e); } if (zipPath != null) { response.setContentType("application/zip"); response.addHeader("Content-Disposition", "attachment; filename=\"test.zip\""); try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(zipPath))) { IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (FileNotFoundException e) { logger.error("Zip file not found", e); } catch (IOException e) { logger.error("Cannot return zip file as an HTTP response", e); } } }
From source file:org.mitre.mpf.mvc.controller.MarkupController.java
@RequestMapping(value = "/markup/content", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) @ResponseBody//from w ww.j a va 2 s . c o m public void serve(HttpServletResponse response, @RequestParam(value = "id", required = true) long id) throws IOException, URISyntaxException { MarkupResult mediaMarkupResult = mpfService.getMarkupResult(id); if (mediaMarkupResult != null) { //only on image! if (!StringUtils.endsWithIgnoreCase(mediaMarkupResult.getMarkupUri(), "avi")) { String nonUrlPath = mediaMarkupResult.getMarkupUri().replace("file:", ""); File f = new File(nonUrlPath); if (f.canRead()) { FileUtils.copyFile(f, response.getOutputStream()); response.flushBuffer(); } } } //TODO need a no image available if final nested if is not met }
From source file:edu.dfci.cccb.mev.controllers.HeatmapController.java
@RequestMapping(value = "/{id}/download", method = GET) @ResponseStatus(OK)/* w w w.j a v a2 s . co m*/ public void download(@PathVariable("id") String id, HttpServletResponse response) throws HeatmapNotFoundException, IOException, AnnotationNotFoundException { response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment;filename=" + id + ".txt"); get(id).toStream(response.getOutputStream()); response.flushBuffer(); }
From source file:com.almende.eve.transport.http.DebugServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { // If this is a handshake request, handle it. if (handleHandShake(req, resp)) { return;/*from w w w . j a va2 s . c o m*/ } final String url = req.getRequestURI(); final String id = getId(url); if (id == null || id.equals("") || id.equals(myUrl.toASCIIString())) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Couldn't parse URL, missing 'id'"); resp.flushBuffer(); return; } if (myUrl != null) { final HttpTransport transport = HttpService.get(myUrl, id); if (transport != null) { // get the resource name from the end of the url String resource = getResource(url); if (resource == null || resource.equals("")) { if (!url.endsWith("/") && !resp.isCommitted()) { final String redirect = url + "/"; resp.sendRedirect(redirect); return; } resource = "index.html"; } final String extension = resource.substring(resource.lastIndexOf('.') + 1); // load the resource final String mimetype = StreamingUtil.getMimeType(extension); final String filename = RESOURCES + resource; final InputStream is = this.getClass().getResourceAsStream(filename); if (is != null) { StreamingUtil.streamBinaryData(is, mimetype, resp); } else { throw new ServletException( "Resource '" + resource + "' not found. (filename:'" + filename + "')"); } resp.flushBuffer(); } else { resp.setContentType("text/plain"); resp.getWriter().println("Agent:" + id + " is unknown!"); resp.getWriter().close(); resp.flushBuffer(); } } else { resp.setContentType("text/plain"); resp.getWriter().println("You've found the servlet for agent:" + id); resp.getWriter().close(); resp.flushBuffer(); } }
From source file:eea.eprtr.cms.controller.FileOpsController.java
/** * Download a file.// www . j a va2 s .c om * Extension is stripped by Spring unless reconfigured. * @see <a href="http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-suffix-pattern-match">Suffix Pattern Matching</a> * @see <a href="http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-config-path-matching">21.16.11 Path Matching</a> */ @RequestMapping(value = "/docs/{file_name}", method = RequestMethod.GET) public void downloadFile(@PathVariable("file_name") String fileId, HttpServletResponse response) throws IOException { long fileSize = 0; InputStream iStream = null; try { fileSize = storageService.getSizeById(fileId, "docs"); iStream = storageService.getById(fileId, "docs"); } catch (Exception e) { throw new java.io.FileNotFoundException(fileId); } response.setContentType("application/octet-stream"); response.setHeader("Content-Length", Long.toString(fileSize)); response.setHeader("Content-Disposition", "attachment; filename=" + fileId); org.apache.commons.io.IOUtils.copy(iStream, response.getOutputStream()); response.flushBuffer(); iStream.close(); }
From source file:it.polimi.diceH2020.launcher.controller.DownloadsController.java
private void respondWithZipFile(@NotNull Map<String, String> files, @NotNull HttpServletResponse response) { File zipPath = null;//ww w.j av a 2s. c o m try { zipPath = fileUtility.createTempZip(files); } catch (IOException e) { logger.error("Problem creating zip file", e); } if (zipPath != null) { response.setContentType("application/zip"); response.addHeader("Content-Disposition", "attachment; filename=\"test.zip\""); try { InputStream is = new FileInputStream(zipPath); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (FileNotFoundException e) { logger.error("Zip file not found", e); } catch (IOException e) { logger.error("Cannot return zip file as an HTTP response", e); } } }