List of usage examples for org.springframework.core.io InputStreamResource InputStreamResource
public InputStreamResource(InputStream inputStream)
From source file:th.co.geniustree.intenship.advisor.controller.IndexController.java
@RequestMapping(value = "/parent/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFileParent(@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 ww w . ja va2 s. c o m }
From source file:com.sitewhere.configuration.ExternalConfigurationResolver.java
@Override public ApplicationContext resolveSiteWhereContext(IVersion version) throws SiteWhereException { try {/*from ww w . j a va2s.c o m*/ String url = getRemoteConfigUrl() + "/sitewhere-server.xml"; LOGGER.info("Loading configuration from external source: " + url); GenericApplicationContext context = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); URL remote = new URL(getRemoteConfigUrl()); reader.loadBeanDefinitions(new InputStreamResource(remote.openStream())); context.refresh(); return context; } catch (Exception e) { throw new SiteWhereException(e); } }
From source file:th.co.geniustree.intenship.advisor.controller.AdviseController.java
@RequestMapping(value = "/getfileadvise/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") FileUpload fileUpload) { ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(fileUpload.getContent().length) .contentType(MediaType.parseMediaType(fileUpload.getMimeType())) .header("Content-Disposition", "attachment; filename=\"" + fileUpload.getName() + "\"") .body(new InputStreamResource(new ByteArrayInputStream(fileUpload.getContent()))); return body;/*from ww w . j a v a 2 s . c o m*/ }
From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java
public static GenericApplicationContext getSpringApplicationContext(String applicationContxtFilePath, ClassLoader springBeansClassLoader) throws AxisFault { GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(springBeansClassLoader); ClassLoader prevCl = Thread.currentThread().getContextClassLoader(); try {/*w w w .j av a 2 s . co m*/ // Save the class loader so that you can restore it later Thread.currentThread().setContextClassLoader( new MultiParentClassLoader(new URL[] {}, new ClassLoader[] { springBeansClassLoader, prevCl })); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false); xbdr.loadBeanDefinitions( new InputStreamResource(new FileInputStream(new File(applicationContxtFilePath)))); appContext.refresh(); } catch (FileNotFoundException e) { throw AxisFault.makeFault(e); } finally { // Restore Thread.currentThread().setContextClassLoader(prevCl); } return appContext; }
From source file:th.co.geniustree.intenship.advisor.controller.BehaviorController.java
@RequestMapping(value = "/getfilebehavior/{id}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> getFile(@PathVariable("id") FileUpload fileUpload) { ResponseEntity<InputStreamResource> body = ResponseEntity.ok().contentLength(fileUpload.getContent().length) .contentType(MediaType.parseMediaType(fileUpload.getMimeType())) .header("Content-Disposition", "attachment; filename=\"" + fileUpload.getName() + "\"") .body(new InputStreamResource(new ByteArrayInputStream(fileUpload.getContent()))); return body;/*from w w w .ja va 2s . c om*/ }
From source file:com.greglturnquist.HomeController.java
private ResponseEntity<?> getRawImage() { try {/*from ww w . j a va2 s.com*/ Resource file = resourceLoader.getResource("file:upload-dir/keep-calm-and-learn-javascript.jpg"); return ResponseEntity.ok().contentLength(file.contentLength()).contentType(MediaType.IMAGE_JPEG) .body(new InputStreamResource(file.getInputStream())); } catch (IOException e) { return ResponseEntity.badRequest().body("Couldn't find it => " + e.getMessage()); } }
From source file:org.leandreck.endpoints.examples.SecondTypeScriptEndpoint.java
@TypeScriptIgnore @RequestMapping(value = "/photos/{id}", method = GET, produces = MediaType.IMAGE_PNG_VALUE) public ResponseEntity<InputStreamResource> getPhoto(@PathVariable Long id) { return ResponseEntity.ok().contentLength(0).contentType(IMAGE_PNG) .body(new InputStreamResource(new ByteArrayInputStream("No Content".getBytes()))); }
From source file:com.orange.clara.cloud.poc.s3.controller.PocS3Controller.java
@RequestMapping(value = "/download/{fileName:.*}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> download(@PathVariable String fileName) throws IOException { Blob blob = this.blobStore.getBlob(fileName); HttpHeaders respHeaders = new HttpHeaders(); respHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); respHeaders.setContentLength(blob.getPayload().getContentMetadata().getContentLength()); respHeaders.setContentDispositionFormData("attachment", fileName); InputStream inputStream = blob.getPayload().openStream(); InputStreamResource isr = new InputStreamResource(inputStream); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); }
From source file:com.formkiq.core.service.entry.WorkflowEntryFlowEventProcessor.java
/** * Render PDF to PNG./*from w w w . jav a2s . co m*/ * @param flow {@link WebFlow} * @return {@link ResponseEntity} * @throws IOException IOException */ public ResponseEntity<InputStreamResource> eventIdrenderedimage(final WebFlow flow) throws IOException { ConversionResult cpng = (ConversionResult) flow.getParameter(PDFCONV); byte[] png = cpng.getData(); return ResponseEntity.ok().contentLength(png.length).contentType(MediaType.IMAGE_PNG) .body(new InputStreamResource(new ByteArrayInputStream(png))); }
From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java
@RequestMapping(method = RequestMethod.GET, value = "/files/{filename}") public ResponseEntity<?> getFile(@PathVariable String filename) throws IOException { Resource file = this.fileService.findOne(filename); try {//from w ww.j a v a 2 s. c o m return ResponseEntity.ok().contentLength(file.contentLength()).contentType(MediaType.IMAGE_JPEG) .body(new InputStreamResource(file.getInputStream())); } catch (IOException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } }