List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
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);/*from www . java2s . c o m*/ }
From source file:com.ibm.BestSellerServlet.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//*from w w w . j a va 2 s . c o m*/ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/json"); response.setCharacterEncoding("UTF-8"); OutputStream stream = response.getOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8"); String listName = request.getParameter("list"); String date = request.getParameter("date"); logger.debug("Requested list {} and requested date {}", listName, date); NewYorkTimes times = new NewYorkTimes(listName, date); try { BestSellerList bestSellers = times.getList(); ObjectMapper mapper = new ObjectMapper(); String listContents = mapper.writeValueAsString(bestSellers.getBooks()); logger.debug("Booklist is {}", listContents); writer.write(listContents); writer.flush(); writer.close(); } catch (Exception e) { logger.error("New York times list unavailable"); throw new IOException("Could not get book list from ny times"); } }
From source file:controllers.BaseParamController.java
@RequestMapping("/getXls") public void getXls(Map<String, Object> model, HttpServletResponse response) throws Exception { response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=BaseParamMap.xls"); baseParamService.getXls().write(response.getOutputStream()); }
From source file:org.magnum.dataup.VideoSvcUp.java
@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.GET) public @ResponseBody void getVideoData(@PathVariable(VideoSvcApi.ID_PARAMETER) long id, HttpServletResponse response) throws IOException { if (!videos.containsKey(id)) { response.setStatus(HttpStatus.NOT_FOUND.value()); } else {// w w w.j av a2 s . c om Video v = videos.get(id); videoDataMgr.copyVideoData(v, response.getOutputStream()); } }
From source file:com.formkiq.web.config.TestDataController.java
/** * Provider Sample generic XML data with text/xml content type. * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @throws IOException IOException/*from w ww .ja va2 s .c om*/ */ @RequestMapping(value = "/testdata/sample-generic2.xml", method = RequestMethod.GET) public void sampleGeneric2(final HttpServletRequest request, final HttpServletResponse response) throws IOException { byte[] data = Resources.getResourceAsBytes("/testdata/sample-generic.xml"); response.setContentType("application/xml"); response.setContentLengthLong(data.length); IOUtils.write(data, response.getOutputStream()); }
From source file:com.gae.ImageServlet.java
@SuppressWarnings("unchecked") public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { MemoryFileItemFactory factory = new MemoryFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); //resp.setContentType("image/png"); ServletOutputStream out = resp.getOutputStream(); try {/*www . ja v a 2 s . c om*/ List<FileItem> list = upload.parseRequest(req); for (FileItem item : list) { if (!(item.isFormField())) { String fileName = item.getName(); //Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req); //BlobKey blobKey = blobs.get("myFile"); if (fileName != null && !"".equals(fileName)) { int size = (int) item.getSize(); byte[] data = new byte[size]; InputStream in = item.getInputStream(); in.read(data); //ImagesService imagesService = ImagesServiceFactory.getImagesService(); /* Image oldImage = ImagesServiceFactory.makeImage(data); Transform resize = ImagesServiceFactory.makeResize(180, 150); Image newImage = imagesService.applyTransform(resize, oldImage, OutputEncoding.PNG); byte[] newImageData = newImage.getImageData(); out.write(newImageData); */ /* Image image = ImagesServiceFactory.makeImage(data); byte[] ImageData = image.getImageData(); */ out.flush(); } } } } catch (FileUploadException e) { e.printStackTrace(); } finally { if (out != null) { out.close(); } } }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); CategoryDataset dataset = createDataset(); JFreeChart chart = getChart(dataset); int width = 400; int height = 250; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }
From source file:com.gsr.myschool.server.reporting.convocation.ConvocationController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/pdf") @ResponseStatus(HttpStatus.OK)/*from ww w .j av a 2 s. c om*/ public void generateConvocation(@RequestParam String number, HttpServletResponse response) { ReportDTO dto = convocationService.generateConvocation(number); try { response.addHeader("Content-Disposition", "attachment; filename=" + dto.getFileName()); BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); byte[] result = reportService.generatePdf(dto); outputStream.write(result, 0, result.length); outputStream.flush(); outputStream.close(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:net.sf.appstatus.web.pages.StatusPage.java
public void doGetJSON(StatusWebHandler webHandler, HttpServletRequest req, HttpServletResponse resp) throws UnsupportedEncodingException, IOException { setup(resp, "application/json"); ServletOutputStream os = resp.getOutputStream(); int statusCode = 200; List<ICheckResult> results = webHandler.getAppStatus().checkAll(req.getLocale()); for (ICheckResult r : results) { if (r.isFatal()) { resp.setStatus(500);//from w w w.j av a 2s. c o m statusCode = 500; break; } } os.write("{".getBytes(ENCODING)); os.write(("\"code\" : " + statusCode + ",").getBytes(ENCODING)); os.write(("\"status\" : {").getBytes(ENCODING)); boolean first = true; for (ICheckResult r : results) { if (!first) { os.write((",").getBytes(ENCODING)); } os.write(("\"" + r.getProbeName() + "\" : " + r.getCode()).getBytes(ENCODING)); if (first) { first = false; } } os.write("}".getBytes(ENCODING)); os.write("}".getBytes(ENCODING)); }
From source file:org.energyos.espi.datacustodian.web.api.ReadingTypeRESTController.java
@RequestMapping(value = Routes.ROOT_READING_TYPE_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody//from w ww . j a v a 2 s. c o m public void index(HttpServletResponse response, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); exportService.exportReadingTypes(response.getOutputStream(), new ExportFilter(params)); }