List of usage examples for org.springframework.core.io InputStreamResource InputStreamResource
public InputStreamResource(InputStream inputStream)
From source file:com.wooki.services.export.ExportServiceImpl.java
public InputStream exportPdf(Long bookId) { if (bookId == null) { throw new IllegalArgumentException("Book id cannot be null to export."); }//from w w w . j a va2s . c om InputStream bookStream = this.inputRenderer.exportBook(bookId); InputStream result = toPdfConvertor.performTransformation(new InputStreamResource(bookStream)); return result; }
From source file:org.kawakicchi.bookshelf.interfaces.page.PageController.java
@ResponseBody @RequestMapping(value = "/{pageSeq:^[0-9]+$}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public Resource file2(@PathVariable("pageSeq") Long pageSeq) { InputStream stream = contentStorage.get("photo/" + pageSeq); return new InputStreamResource(stream); }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
public static GenericApplicationContext getSpringApplicationContextClassPath(ClassLoader classLoader, String relPath) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try {//from w ww . j a v a 2 s .c om Thread.currentThread().setContextClassLoader(classLoader); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); InputStream in = classLoader.getResourceAsStream(relPath); if (in == null) { throw new AxisFault("Spring context cannot be located for AxisService"); } xbdr.loadBeanDefinitions(new InputStreamResource(in)); appContext.refresh(); } catch (Exception e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
From source file:com.wooki.services.export.ExportServiceImpl.java
public InputStream exportLatex(Long bookId) { if (bookId == null) { throw new IllegalArgumentException("Book id cannot be null to export."); }//from w ww . ja v a 2 s .c om /** Generate Latex */ InputStream bookStream = this.inputRenderer.exportBook(bookId); InputStream xhtml = toXHTMLConvertor.performTransformation(new InputStreamResource(bookStream)); InputStream improvedXhtml = toImprovedXHTML4LatexConvertor .performTransformation(new InputStreamResource(xhtml)); InputStream latex = toLatexConvertor.performTransformation(new InputStreamResource(improvedXhtml)); return latex; }
From source file:th.co.geniustree.intenship.advisor.controller.IndexController.java
@RequestMapping(value = "/student/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFileStudent(@PathVariable("id") FileUpload uploadFile) { ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(uploadFile.getContent().length) .contentType(MediaType.parseMediaType(uploadFile.getMimeType())) .header("Content-Disposition", "attachment; filename=\"" + uploadFile.getName() + "\"") .body(new InputStreamResource(new ByteArrayInputStream(uploadFile.getContent()))); return body;//from w ww . j a v a 2s . c o m }
From source file:org.eclipse.swordfish.core.test.util.base.TargetPlatformOsgiTestCase.java
@Override protected Resource getTestingFrameworkBundlesConfiguration() { try {// w w w .j a v a 2 s . com return new InputStreamResource(TargetPlatformOsgiTestCase.class.getClassLoader() .getResource("boot-bundles.properties").openStream()); } catch (IOException ex) { throw new IllegalStateException(ex); } }
From source file:com.mycompany.testdowload.controller.DocumentFileController.java
@RequestMapping(value = "/getfile/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") UploadFile uploadFile) { ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(uploadFile.getContent().length) .contentType(MediaType.parseMediaType(uploadFile.getMimeType())) .header("Content-Disposition", "attachment; filename=\"" + uploadFile.getName() + "\"") .body(new InputStreamResource(new ByteArrayInputStream(uploadFile.getContent()))); return body;//from w w w.jav a2 s. c om }
From source file:business.services.PaNumberService.java
public HttpEntity<InputStreamResource> writePaNumbers(List<PathologyItem> items, Integer labNumber, String labRequestCode) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING); CSVWriter csvwriter = new CSVWriter(writer, ';', '"'); csvwriter.writeNext(FILE_HEADER);/*w w w .j a va2s. co m*/ for (PathologyItem item : items) { log.info(item.getPaNumber()); String[] toppings = { labNumber.toString(), item.getPaNumber(), "", "" }; csvwriter.writeNext(toppings); } String filename = "panumbers_" + labRequestCode + ".csv"; try { csvwriter.flush(); writer.flush(); out.flush(); InputStream in = new ByteArrayInputStream(out.toByteArray()); csvwriter.close(); writer.close(); out.close(); InputStreamResource resource = new InputStreamResource(in); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING)); headers.set("Content-Disposition", "attachment; filename=\"" + filename + "\""); HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; } catch (IOException e) { throw new Exception(e); } }
From source file:edu.eci.cosw.postresYa.controller.ActivityController.java
/** * Busca la imagen a un postre asociado por medio de un cdigo dado * @param code//w ww . j a va2 s . com * @return ResponseEntity */ @RequestMapping(value = "/{code}/picture", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getPostrePicture(@PathVariable String code) { try { return ResponseEntity.ok().contentType(MediaType.parseMediaType("image/jpg")) .body(new InputStreamResource(stub.getPostrePicture(code))); } catch (Exception e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }
From source file:org.lexevs.tree.service.ApplicationContextFactory.java
/** * Instantiates a new application context factory. *//*from w w w. ja v a2 s . com*/ protected ApplicationContextFactory() { GenericApplicationContext ctx = new GenericApplicationContext(); ctx.setClassLoader(MyClassLoader.instance()); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); InputStream stream = MyClassLoader.instance().getResourceAsStream("treeServiceContext.xml"); xmlReader.loadBeanDefinitions(new InputStreamResource(stream)); ctx.refresh(); this.context = ctx; }