List of usage examples for javax.servlet.http HttpServletResponse flushBuffer
public void flushBuffer() throws IOException;
From source file:com.digitalizat.control.TdocController.java
@RequestMapping(value = "obtenerMiniatura") public void obtenerMiniatura(@RequestParam(value = "codigo", required = true) String codigo, HttpServletResponse response) throws FileNotFoundException, IOException, Exception { Integer cod = null;/*from w ww .j a v a 2s . c o m*/ try { cod = Integer.valueOf(codigo); } catch (Exception e) { } if (cod != null) { Document doc = tdocManager.getDocument(Integer.valueOf(codigo)); String salida = ThumbnailCreator.createThumbnail(doc.getBasePath(), doc.getFileName()); response.setContentType("image/png"); response.setHeader("Content-Disposition", "attachment; filename=" + doc.getFileName() + ".png"); InputStream is = new FileInputStream(salida); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } }
From source file:org.kaaproject.kaa.sandbox.web.servlet.ProjectFileServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ProjectDataKey key = extractKey(request); if (key != null) { try {//from w ww . ja v a 2s .c o m FileData fileData = cacheService.getProjectFile(key); if (fileData != null) { if (fileData.getContentType() != null) { response.setContentType(fileData.getContentType()); } ServletUtils.prepareDisposition(request, response, fileData.getFileName()); response.setContentLength(fileData.getFileData().length); response.setBufferSize(BUFFER); response.getOutputStream().write(fileData.getFileData()); response.flushBuffer(); } else { logger.error("File data not found in cache for requested parameters: projectId [{}] type [{}]", key.getProjectId(), key.getProjectDataType()); } } catch (Exception e) { logger.error("Unexpected error in ProjectFileServlet.doGet: ", e); } } }
From source file:com.log4ic.compressor.utils.Compressor.java
/** * ??// ww w . j a v a 2 s . c o m * * @param code * @param type * @param response * @throws com.log4ic.compressor.exception.CompressionException * */ private static void writeOutCode(String code, FileType type, HttpServletResponse response) throws CompressionException { //mine type try { switch (type) { case JS: response.setContentType("text/javascript"); break; case CSS: case GSS: case LESS: case MSS: response.setContentType("text/css"); break; default: response.setContentType("text/html"); } PrintWriter writer = response.getWriter(); writer.write(code); writer.flush(); response.flushBuffer(); } catch (IOException e) { throw new CompressionException("Write code to client error.", e); } }
From source file:com.motorola.motoask.gcm.RegisterServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { JSONObject jsonResp = new JSONObject(); String regId, tbdId, email, os; try {/*from ww w . j av a 2s . c o m*/ regId = getParameter(req, PARAMETER_REG_ID); tbdId = getParameter(req, PARAMETER_USER_ID); email = getParameter(req, PARAMETER_EMAIL); // boolean temp = EnumUtils.isValidEnum(Constants.DEVICE_OS.class, os); if (regId == null || tbdId == null || regId.length() == 0 || tbdId.length() == 0 || email == null || email.length() == 0) { setFail(resp); jsonResp.put("success", false); jsonResp.put("message", "bad or missing param"); resp.getWriter().write(jsonResp.toString()); resp.flushBuffer(); return; } log.info("registering device for " + email); if (Datastore.register(tbdId, email, regId)) { setSuccess(resp); jsonResp.put("success", true); } else { setFail(resp); jsonResp.put("success", false); } resp.getWriter().write(jsonResp.toString()); resp.flushBuffer(); } catch (Exception e) { resp.setStatus(400); log.severe("fail to register device: " + e.toString()); } }
From source file:org.nuxeo.ecm.core.io.download.DownloadServiceImpl.java
protected void transferBlobWithByteRange(Blob blob, ByteRange byteRange, HttpServletResponse response) throws UncheckedIOException { transferBlobWithByteRange(blob, byteRange, () -> { try {/* www . jav a 2s. c o m*/ return response.getOutputStream(); } catch (IOException e) { throw new UncheckedIOException(e); } }); try { response.flushBuffer(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.emergya.persistenceGeo.web.RestResourcesController.java
/** * This method loads a resource from server * /* ww w .j a va 2 s. c o m*/ * @param resourceId * * @return JSON file with resource */ @RequestMapping(value = "/persistenceGeo/getResource/{resourceId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) public void getResource(@PathVariable String resourceId, HttpServletResponse response) { try { Long accessId = Long.decode(resourceId.split("_")[0]); ResourceDto resource = loadFiles.get(accessId); if (resource == null) { // not loaded yet resource = resourceService.getByAccessId(accessId); loadFiles.put(accessId, resource); } response.setContentType(resource.getType()); response.setHeader("Content-Length", new Long(resource.getSize()).toString()); response.setHeader("Content-Disposition", "inline; filename=" + resource.getName()); IOUtils.copy(new FileInputStream(resource.getData()), response.getOutputStream()); response.flushBuffer(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.geoserver.backuprestore.rest.BackupController.java
@GetMapping(path = "backup/{backupId:.+}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.ALL_VALUE }) public Object backupGet(@RequestParam(name = "format", required = false) String format, @PathVariable String backupId, HttpServletResponse response) { Object lookup = lookupBackupExecutionsContext(getExecutionIdFilter(backupId), true, false); if (lookup != null) { if (lookup instanceof BackupExecutionAdapter) { if (backupId.endsWith(".zip")) { try { // get your file as InputStream File file = ((BackupExecutionAdapter) lookup).getArchiveFile().file(); InputStream is = new FileInputStream(file); // copy it to response's OutputStream org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { LOGGER.log(Level.INFO, "Error writing file to output stream.", ex); throw new RuntimeException("IOError writing file to output stream"); }//from www. java2s . c om } else { return wrapObject((BackupExecutionAdapter) lookup, BackupExecutionAdapter.class); } } else { return wrapList((List<BackupExecutionAdapter>) lookup, BackupExecutionAdapter.class); } } return null; }
From source file:org.geoserver.backuprestore.rest.RestoreController.java
@GetMapping(path = "restore/{restoreId:.+}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.ALL_VALUE }) public Object restoreGet(@RequestParam(name = "format", required = false) String format, @PathVariable String restoreId, HttpServletResponse response) { Object lookup = lookupRestoreExecutionsContext(getExecutionIdFilter(restoreId), true, false); if (lookup != null) { if (lookup instanceof RestoreExecutionAdapter) { if (restoreId.endsWith(".zip")) { try { // get your file as InputStream File file = ((RestoreExecutionAdapter) lookup).getArchiveFile().file(); InputStream is = new FileInputStream(file); // copy it to response's OutputStream org.apache.commons.io.IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { LOGGER.log(Level.INFO, "Error writing file to output stream.", ex); throw new RuntimeException("IOError writing file to output stream"); }/* w w w . j a v a 2 s . co m*/ } else { return wrapObject((RestoreExecutionAdapter) lookup, RestoreExecutionAdapter.class); } } else { return wrapList((List<RestoreExecutionAdapter>) lookup, RestoreExecutionAdapter.class); } } return null; }