List of usage examples for javax.servlet.http HttpServletResponse getOutputStream
public ServletOutputStream getOutputStream() throws IOException;
From source file:info.magnolia.rendering.engine.RenderingFilter.java
/** * Send data as is.//from w ww. j a va 2s . c o m * @param is Input stream for the resource * @param response HttpServletResponse as received by the service method * @throws IOException standard servlet exception */ private void sendUnCompressed(InputStream is, HttpServletResponse response) throws IOException { ServletOutputStream os = response.getOutputStream(); byte[] buffer = new byte[8192]; int read; while ((read = is.read(buffer)) > 0) { os.write(buffer, 0, read); } os.flush(); IOUtils.closeQuietly(os); }
From source file:org.fusesource.restygwt.server.complex.DTOImplementationServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { DTOImplementation impl = new DTOImplementation(); impl.setName("implementation"); resp.setContentType("application/json"); ObjectMapper om = new ObjectMapper(); try {//from w ww . j a va2s . c om om.writeValue(resp.getOutputStream(), impl); } catch (Exception e) { throw new ServletException(e); } }
From source file:com.zhenhappy.ems.action.user.VisaAction.java
@RequestMapping(value = "/visa/visaZhengjian", method = RequestMethod.GET) public void visaPage(@RequestParam("vid") Integer vid, @RequestParam("type") Integer type, HttpServletResponse response) { try {//www.j a v a2s. c om TVisa image = visaService.queryByVid(vid); if (image != null) { OutputStream outputStream = response.getOutputStream(); File img = null; if (type.intValue() == 1) { img = new File(image.getPassportPage()); } else { img = new File(image.getBusinessLicense()); } if (!img.exists()) { return; } FileUtils.copyFile(img, outputStream); outputStream.close(); outputStream.flush(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gov.nih.nci.caintegrator.web.action.StudyLogoResult.java
/** * {@inheritDoc}/*from www . j a va 2 s .c o m*/ */ public void execute(ActionInvocation invocation) throws IOException { StudyLogo studyLogo = SessionHelper.getInstance().getDisplayableUserWorkspace().getStudyLogo(); HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String imagePath = ""; imagePath = retrieveImagePath(request, response, studyLogo); OutputStream outputStream = response.getOutputStream(); File imageFile = new File(imagePath); FileInputStream inputStream = new FileInputStream(imageFile); IOUtils.copy(inputStream, outputStream); outputStream.close(); }
From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSignedPdf.java
/** * Writes the PDF document to the browser * @param sf the container//from www .ja va 2s . c o m * @param response the response * @throws IOException */ private void writeRaw(SignedForm sf, HttpServletResponse response) throws IOException { InputStream is = new ByteArrayInputStream(sf.getDocument()); ServletOutputStream outs = null; try { outs = response.getOutputStream(); int r = 0; byte[] chunk = new byte[8192]; while ((r = is.read(chunk)) != -1) { outs.write(chunk, 0, r); } outs.flush(); } finally { IOUtils.closeQuietly(outs); } }
From source file:com.googlesource.gerrit.plugins.lfs.fs.LfsFsContentServlet.java
private void getObject(HttpServletRequest req, HttpServletResponse rsp, Optional<AnyLongObjectId> obj) throws IOException { if (obj.isPresent()) { AsyncContext context = req.startAsync(); context.setTimeout(timeout);/*from ww w .j a v a 2 s .c o m*/ rsp.getOutputStream().setWriteListener(new ObjectDownloadListener(repository, context, rsp, obj.get())); } }
From source file:com.nsano.uat.Imtservlet.java
/** * * @param request//from w w w .j a v a 2 s . c o m * @param response * @throws ServletException , IOException */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); response.setContentType("text/plain;charset=UTF-8"); response.setDateHeader("Expires", new Date().getTime()); // Expiration // date response.setDateHeader("Date", new Date().getTime()); // Date and time try { // that the // message was // sent out.write(moneytransfer(request).getBytes()); } catch (JSONException ex) { Logger.getLogger(IMTCredit.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(Imtservlet.class.getName()).log(Level.SEVERE, null, ex); } out.flush(); out.close(); }
From source file:com.nominanuda.springmvc.StaticViewResolver.java
public View resolveViewName(String viewName, Locale locale) throws Exception { URL url = resolve(viewName, locale); if (url == null) { return null; } else {//ww w. j a va 2s . c o m if (cache) { View cv = findCachedView(url); if (cv != null) { return cv; } } final byte[] barr = io.readAndClose(url.openStream()); View v = new View() { public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentLength(barr.length); response.setContentType(contentType); OutputStream os = response.getOutputStream(); os.write(barr); os.flush(); } public String getContentType() { return contentType; } }; if (cache) { storeCachedView(url, v); } return v; } }
From source file:com.indeed.imhotep.web.TokenizeController.java
@RequestMapping("/tokenize") @ResponseBody/*from w ww . ja v a 2 s . c o m*/ protected void handleTokenize(@RequestParam("q") String query, HttpServletResponse resp) throws IOException { resp.setHeader("Access-Control-Allow-Origin", "*"); try { final List<Token> tokens = TerminalParser.LEXER.parse(query); final ServletOutputStream outputStream = resp.getOutputStream(); resp.setContentType(MediaType.APPLICATION_JSON_VALUE); final ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); final ObjectNode jsonRoot = mapper.createObjectNode(); final ArrayNode tokenArrayNode = jsonRoot.arrayNode(); jsonRoot.put("tokens", tokenArrayNode); for (Token token : tokens) { final ObjectNode tokenNode = tokenArrayNode.objectNode(); final String text = token.value() instanceof Tokens.Fragment ? ((Tokens.Fragment) token.value()).text() : (String) token.value(); final String tag = token.value() instanceof Tokens.Fragment ? ((Tokens.Fragment) token.value()).tag().toString() : "STRING"; tokenNode.put("text", text); tokenNode.put("index", token.index()); tokenNode.put("length", token.length()); tokenNode.put("tag", tag); tokenArrayNode.add(tokenNode); } mapper.writeValue(outputStream, jsonRoot); outputStream.close(); } catch (Throwable e) { QueryServlet.handleError(resp, true, e, false, false); } }
From source file:controllers.ColorGroupController.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=ColorGroup.xls"); colorGroupService.getXls().write(response.getOutputStream()); }