List of usage examples for javax.servlet ServletOutputStream flush
public void flush() throws IOException
From source file:au.org.ala.biocache.web.MapController.java
private void displayBlankImage(int width, int height, boolean useBase, HttpServletResponse response) { try {//from www .j av a 2 s . c o m response.setContentType("image/png"); BufferedImage baseImage = null; if (useBase) { baseImage = createBaseMapImage(); } else { baseImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(baseImage, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image", e); } }
From source file:au.org.ala.biocache.web.MapController.java
@RequestMapping(value = "/occurrences/legend", method = RequestMethod.GET) public void pointLegendImage( @RequestParam(value = "colourby", required = false, defaultValue = "0") Integer colourby, @RequestParam(value = "width", required = false, defaultValue = "50") Integer widthObj, @RequestParam(value = "height", required = false, defaultValue = "50") Integer heightObj, HttpServletResponse response) {//from w w w . j a v a 2s. c om try { int width = widthObj.intValue(); int height = heightObj.intValue(); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) img.getGraphics(); if (colourby != null) { int colour = 0xFF000000 | colourby.intValue(); Color c = new Color(colour); g.setPaint(c); } else { g.setPaint(Color.blue); } g.fillOval(0, 0, width, width); g.dispose(); response.setContentType("image/png"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image", e); } }
From source file:net.nan21.dnet.core.web.controller.AbstractDnetController.java
protected void sendFile(InputStream inputStream, ServletOutputStream outputStream, int bufferSize) throws IOException { try {/* w w w. j av a 2s. c o m*/ byte[] buf = new byte[bufferSize]; int bytesRead; while ((bytesRead = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, bytesRead); } } finally { if (inputStream != null) inputStream.close(); } outputStream.flush(); }
From source file:org.apache.stratos.logging.view.ui.LogViewerClient.java
public void downloadArchivedLogFiles(String logFile, HttpServletResponse response, String domain, String serverKey) throws Exception { try {//from w w w . ja va 2 s . co m logFile = logFile.replace(".gz", ""); ServletOutputStream outputStream = response.getOutputStream(); response.setContentType("application/txt"); response.setHeader("Content-Disposition", "attachment;filename=" + logFile.replaceAll("\\s", "_")); DataHandler data = stub.downloadArchivedLogFiles(logFile, domain, serverKey); InputStream fileToDownload = data.getInputStream(); int c; while ((c = fileToDownload.read()) != -1) { outputStream.write(c); } outputStream.flush(); outputStream.flush(); } catch (Exception e) { String msg = "Error occurred while getting logger data. Backend service may be unavailable"; log.error(msg, e); throw e; } }
From source file:au.org.ala.biocache.web.MapController.java
/** * This method creates and renders a density map legend for a species. * /*from w w w .j a v a2 s. c o m*/ * @throws Exception */ @RequestMapping(value = "/density/legend", method = RequestMethod.GET) public @ResponseBody void speciesDensityLegend(SpatialSearchRequestParams requestParams, @RequestParam(value = "forceRefresh", required = false, defaultValue = "false") boolean forceRefresh, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("image/png"); File baseDir = new File(heatmapOutputDir); String outputHMFile = getOutputFile(request); //Does file exist on disk? File f = new File(baseDir + "/" + "legend_" + outputHMFile); if (!f.isFile() || !f.exists() || forceRefresh) { //If not, generate logger.debug("regenerating heatmap legend"); generateStaticHeatmapImages(requestParams, true, false, 0, "0000ff", null, null, 1.0f, request); } else { logger.debug("legend file already exists on disk, sending file back to user"); } //read file off disk and send back to user try { File file = new File(baseDir + "/" + "legend_" + outputHMFile); //only send the image back if it actually exists - a legend won't exist if we create the map based on points if (file.exists()) { BufferedImage img = ImageIO.read(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } } catch (Exception e) { logger.error("Unable to write image.", e); } }
From source file:org.eclipse.userstorage.tests.util.USSServer.java
protected void retrieveBlob(HttpServletRequest request, HttpServletResponse response, File blobFile, File etagFile, boolean exists) throws IOException { if (!exists) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;//ww w . j a va 2 s . co m } String etag = IOUtil.readUTF(etagFile); String ifNoneMatch = getETag(request, "If-None-Match"); if (ifNoneMatch != null && ifNoneMatch.equals(etag)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json"); response.setHeader("ETag", "\"" + etag + "\""); InputStream body = JSONUtil.build(Collections.singletonMap("value", new FileInputStream(blobFile))); try { ServletOutputStream out = response.getOutputStream(); IOUtil.copy(body, out); out.flush(); } finally { IOUtil.closeSilent(body); } }
From source file:au.org.ala.biocache.web.MapController.java
/** * This method creates and renders a density map for a species. * /* w ww. j ava 2 s . c o m*/ * @throws Exception */ @RequestMapping(value = { "/density/map", "/occurrences/static" }, method = RequestMethod.GET) public @ResponseBody void speciesDensityMap(SpatialSearchRequestParams requestParams, @RequestParam(value = "forceRefresh", required = false, defaultValue = "false") boolean forceRefresh, @RequestParam(value = "forcePointsDisplay", required = false, defaultValue = "false") boolean forcePointsDisplay, @RequestParam(value = "pointColour", required = false, defaultValue = "0000ff") String pointColour, @RequestParam(value = "colourByFq", required = false, defaultValue = "") String colourByFqCSV, @RequestParam(value = "colours", required = false, defaultValue = "") String coloursCSV, @RequestParam(value = "pointHeatMapThreshold", required = false, defaultValue = "500") Integer pointHeatMapThreshold, @RequestParam(value = "opacity", required = false, defaultValue = "1.0") Float opacity, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("image/png"); File outputDir = new File(heatmapOutputDir); if (!outputDir.exists()) { FileUtils.forceMkdir(outputDir); } //output heatmap path String outputHMFile = getOutputFile(request); String[] facetValues = null; String[] facetColours = null; if (StringUtils.trimToNull(colourByFqCSV) != null && StringUtils.trimToNull(coloursCSV) != null) { facetValues = colourByFqCSV.split(","); facetColours = coloursCSV.split(","); if (facetValues.length == 0 || facetValues.length != facetColours.length) { throw new IllegalArgumentException( String.format("Mismatch in facet values and colours. Values: %d, Colours: %d", facetValues.length, facetColours.length)); } } //Does file exist on disk? File f = new File(outputDir + "/" + outputHMFile); if (!f.isFile() || !f.exists() || forceRefresh) { logger.debug("Regenerating heatmap image"); //If not, generate generateStaticHeatmapImages(requestParams, false, forcePointsDisplay, pointHeatMapThreshold, pointColour, facetValues, facetColours, opacity, request); } else { logger.debug("Heatmap file already exists on disk, sending file back to user"); } try { //read file off disk and send back to user File file = new File(outputDir + "/" + outputHMFile); BufferedImage img = ImageIO.read(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image.", e); } }
From source file:org.eclipse.userstorage.tests.util.USSServer.java
protected void login(HttpServletRequest request, HttpServletResponse response) throws IOException { Map<String, Object> requestObject = JSONUtil.parse(request.getInputStream(), null); String username = (String) requestObject.get("username"); String password = (String) requestObject.get("password"); User user = users.get(username);/*w ww .ja v a 2s. c o m*/ if (user == null || password == null || !password.equals(user.getPassword())) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json"); Session session = addSession(user); Cookie cookie = new Cookie("SESSION", session.getID()); cookie.setPath("/"); response.addCookie(cookie); Map<String, Object> responseObject = new LinkedHashMap<String, Object>(); responseObject.put("sessid", session.getID()); responseObject.put("token", session.getCSRFToken()); InputStream body = JSONUtil.build(responseObject); try { ServletOutputStream out = response.getOutputStream(); IOUtil.copy(body, out); out.flush(); } finally { IOUtil.closeSilent(body); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.student.onlineTests.StudentTestsAction.java
public ActionForward exportChecksum(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final String logId = request.getParameter("logId"); final User userView = getUserView(request); if (logId != null && logId.length() != 0) { StudentTestLog studentTestLog = FenixFramework.getDomainObject(logId); if (studentTestLog.getStudent().getPerson().equals(userView.getPerson())) { List<StudentTestLog> studentTestLogs = new ArrayList<StudentTestLog>(); studentTestLogs.add(studentTestLog); byte[] data = ReportsUtils.exportToPdfFileAsByteArray( "net.sourceforge.fenixedu.domain.onlineTests.StudentTestLog.checksumReport", null, studentTestLogs);//from www .j ava 2s . c o m response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=" + studentTestLog.getStudent().getNumber() + ".pdf"); response.setContentLength(data.length); ServletOutputStream writer = response.getOutputStream(); writer.write(data); writer.flush(); writer.close(); response.flushBuffer(); return mapping.findForward(""); } } return null; }
From source file:org.fenixedu.academic.ui.struts.action.student.onlineTests.StudentTestsAction.java
public ActionForward exportChecksum(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { final String logId = request.getParameter("logId"); final User userView = getUserView(request); if (logId != null && logId.length() != 0) { StudentTestLog studentTestLog = FenixFramework.getDomainObject(logId); if (studentTestLog.getStudent().getPerson().equals(userView.getPerson())) { List<StudentTestLog> studentTestLogs = new ArrayList<StudentTestLog>(); studentTestLogs.add(studentTestLog); byte[] data = ReportsUtils .generateReport("org.fenixedu.academic.domain.onlineTests.StudentTestLog.checksumReport", null, studentTestLogs) .getData();/* w ww. j a va 2 s . c o m*/ response.setContentType("application/pdf"); response.addHeader("Content-Disposition", "attachment; filename=" + studentTestLog.getStudent().getNumber() + ".pdf"); response.setContentLength(data.length); ServletOutputStream writer = response.getOutputStream(); writer.write(data); writer.flush(); writer.close(); response.flushBuffer(); return mapping.findForward(""); } } return null; }