List of usage examples for org.springframework.core.io InputStreamResource InputStreamResource
public InputStreamResource(InputStream inputStream)
From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java
private ResponseEntity<InputStreamResource> getJsonResponse(String result) { HttpHeaders respHeaders = new HttpHeaders(); try {//w w w . j a v a 2 s . c o m InputStreamResource isr = new InputStreamResource(toInputStream(result, "UTF-8")); respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); } catch (Exception e) { throw new RuntimeException("IO Error writing file to output stream", e); } }
From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java
private ResponseEntity<InputStreamResource> getFileDownloadResponse(CommandResult commandResult) { HttpHeaders respHeaders = new HttpHeaders(); Path filePath = commandResult.getFileToDownload(); try {/*from w w w . j a va 2 s . c om*/ InputStreamResource isr = new InputStreamResource(new FileInputStream(filePath.toFile())); respHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE); return new ResponseEntity<>(isr, respHeaders, HttpStatus.OK); } catch (Exception e) { throw new RuntimeException("IO Error writing file to output stream", e); } finally { FileUtils.deleteQuietly(filePath.toFile()); } }
From source file:org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.java
/** * @param stream Input stream containing Spring XML configuration. * @return Context.//from w w w. ja v a 2 s. c o m * @throws IgniteCheckedException In case of error. */ private ApplicationContext initContext(InputStream stream) throws IgniteCheckedException { GenericApplicationContext springCtx; try { springCtx = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); springCtx.refresh(); } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException( "Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) ", e); else throw new IgniteCheckedException( "Failed to instantiate Spring XML application context" + ", err=" + e.getMessage() + ']', e); } return springCtx; }
From source file:org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.java
/** * Creates Spring application context. Optionally excluded properties can be specified, * it means that if such a property is found in {@link org.apache.ignite.configuration.IgniteConfiguration} * then it is removed before the bean is instantiated. * For example, {@code streamerConfiguration} can be excluded from the configs that Visor uses. * * @param cfgStream Stream where config file is located. * @param excludedProps Properties to be excluded. * @return Spring application context./* w ww.j a v a2 s . c o m*/ * @throws IgniteCheckedException If configuration could not be read. */ public static ApplicationContext applicationContext(InputStream cfgStream, final String... excludedProps) throws IgniteCheckedException { try { GenericApplicationContext springCtx = prepareSpringContext(excludedProps); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(springCtx); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(cfgStream)); springCtx.refresh(); return springCtx; } catch (BeansException e) { if (X.hasCause(e, ClassNotFoundException.class)) throw new IgniteCheckedException( "Failed to instantiate Spring XML application context " + "(make sure all classes used in Spring configuration are present at CLASSPATH) ", e); else throw new IgniteCheckedException( "Failed to instantiate Spring XML application context [err=" + e.getMessage() + ']', e); } }
From source file:org.apache.kylin.rest.security.PasswordPlaceholderConfigurer.java
/** * The PasswordPlaceholderConfigurer will read Kylin properties as the Spring resource *//*from w w w . j a v a 2 s .co m*/ public PasswordPlaceholderConfigurer() throws IOException { Resource[] resources = new Resource[1]; //Properties prop = KylinConfig.getKylinProperties(); Properties prop = getAllKylinProperties(); StringWriter writer = new StringWriter(); prop.store(new PrintWriter(writer), "kylin properties"); String propString = writer.getBuffer().toString(); IOUtils.closeQuietly(writer); InputStream is = IOUtils.toInputStream(propString, Charset.defaultCharset()); resources[0] = new InputStreamResource(is); this.setLocations(resources); }
From source file:org.apache.synapse.mediators.spring.SpringMediator.java
private synchronized void buildAppContext(MessageContext synCtx) { log.debug("Creating Spring ApplicationContext from property key : " + configKey); GenericApplicationContext appContext = new GenericApplicationContext(); XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext); xbdr.setValidating(false);/*from w w w.j a va 2 s . c o m*/ xbdr.loadBeanDefinitions(new InputStreamResource( Util.getStreamSource(synCtx.getConfiguration().getProperty(configKey)).getInputStream())); appContext.refresh(); this.appContext = appContext; }
From source file:org.egov.infra.utils.FileStoreUtils.java
public ResponseEntity<InputStreamResource> fileAsResponseEntity(String fileStoreId, String moduleName, boolean toSave) { try {/*from w w w. ja va2 s . co m*/ Optional<FileStoreMapper> fileStoreMapper = getFileStoreMapper(fileStoreId); if (fileStoreMapper.isPresent()) { Path file = getFileAsPath(fileStoreId, moduleName); byte[] fileBytes = Files.readAllBytes(file); String contentType = isBlank(fileStoreMapper.get().getContentType()) ? Files.probeContentType(file) : fileStoreMapper.get().getContentType(); return ResponseEntity.ok().contentType(parseMediaType(defaultIfBlank(contentType, JPG_MIME_TYPE))) .cacheControl(CacheControl.noCache()).contentLength(fileBytes.length) .header(CONTENT_DISPOSITION, format(toSave ? CONTENT_DISPOSITION_ATTACH : CONTENT_DISPOSITION_INLINE, fileStoreMapper.get().getFileName())) .body(new InputStreamResource(new ByteArrayInputStream(fileBytes))); } return ResponseEntity.notFound().build(); } catch (IOException e) { LOGGER.error("Error occurred while creating response entity from file mapper", e); return ResponseEntity.badRequest().build(); } }
From source file:org.egov.infra.utils.FileStoreUtils.java
public ResponseEntity<InputStreamResource> fileAsPDFResponse(String fileStoreId, String fileName, String moduleName) {//from ww w. java2 s . c o m try { File file = fileStoreService.fetch(fileStoreId, moduleName); byte[] fileBytes = FileUtils.readFileToByteArray(file); return ResponseEntity.ok().contentType(parseMediaType(APPLICATION_PDF_VALUE)) .cacheControl(CacheControl.noCache()).contentLength(fileBytes.length) .header(CONTENT_DISPOSITION, format(CONTENT_DISPOSITION_INLINE, fileName + ".pdf")) .body(new InputStreamResource(new ByteArrayInputStream(fileBytes))); } catch (IOException e) { throw new ApplicationRuntimeException("Error while reading file", e); } }
From source file:org.kuali.rice.krad.datadictionary.ReloadingDataDictionary.java
public void urlContentChanged(final URL url) { LOG.info("reloading dictionary configuration for " + url.toString()); try {// w w w . j a v a 2 s. co m InputStream urlStream = url.openStream(); InputStreamResource resource = new InputStreamResource(urlStream); int originalValidationMode = xmlReader.getValidationMode(); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlReader.loadBeanDefinitions(resource); xmlReader.setValidationMode(originalValidationMode); UifBeanFactoryPostProcessor factoryPostProcessor = new UifBeanFactoryPostProcessor(); factoryPostProcessor.postProcessBeanFactory(ddBeans); // re-index ddIndex.run(); } catch (Exception e) { LOG.info("Exception in dictionary hot deploy: " + e.getMessage(), e); } }
From source file:org.kuali.rice.krad.devtools.datadictionary.ReloadingDataDictionary.java
public void urlContentChanged(final URL url) { LOG.info("reloading dictionary configuration for " + url.toString()); try {/*from w w w . j a v a 2 s . c o m*/ InputStream urlStream = url.openStream(); InputStreamResource resource = new InputStreamResource(urlStream); List<String> beforeReloadBeanNames = Arrays.asList(ddBeans.getBeanDefinitionNames()); int originalValidationMode = xmlReader.getValidationMode(); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlReader.loadBeanDefinitions(resource); xmlReader.setValidationMode(originalValidationMode); List<String> afterReloadBeanNames = Arrays.asList(ddBeans.getBeanDefinitionNames()); List<String> addedBeanNames = ListUtils.removeAll(afterReloadBeanNames, beforeReloadBeanNames); String namespace = KRADConstants.DEFAULT_NAMESPACE; if (urlToNamespaceMapping.containsKey(url.toString())) { namespace = urlToNamespaceMapping.get(url.toString()); } ddIndex.addBeanNamesToNamespace(namespace, addedBeanNames); performDictionaryPostProcessing(true); } catch (Exception e) { LOG.info("Exception in dictionary hot deploy: " + e.getMessage(), e); } }