public static ProcessEngineConfiguration parseProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName) { Resource springResource = new InputStreamResource(inputStream); return parseProcessEngineConfiguration(springResource, beanName); }
@Override protected Resource decodeDataBuffer(DataBuffer dataBuffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { byte[] bytes = new byte[dataBuffer.readableByteCount()]; dataBuffer.read(bytes); DataBufferUtils.release(dataBuffer); if (logger.isDebugEnabled()) { logger.debug(Hints.getLogPrefix(hints) + "Read " + bytes.length + " bytes"); } Class<?> clazz = elementType.toClass(); if (clazz == InputStreamResource.class) { return new InputStreamResource(new ByteArrayInputStream(bytes)); } else if (Resource.class.isAssignableFrom(clazz)) { return new ByteArrayResource(bytes); } else { throw new IllegalStateException("Unsupported resource class: " + clazz); } }
/** * The PasswordPlaceholderConfigurer will read Kylin properties as the Spring resource */ 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); }
@RequestMapping(value = "/stuff/{stuffId}", method = RequestMethod.GET) public ResponseEntity<InputStreamResource> downloadStuff(@PathVariable int stuffId) throws IOException { String fullPath = stuffService.figureOutFileNameFor(stuffId); File file = new File(fullPath); HttpHeaders respHeaders = new HttpHeaders(); respHeaders.setContentType("application/pdf"); respHeaders.setContentLength(12345678); respHeaders.setContentDispositionFormData("attachment", "fileNameIwant.pdf"); InputStreamResource isr = new InputStreamResource(new FileInputStream(file)); return new ResponseEntity<InputStreamResource>(isr, respHeaders, HttpStatus.OK); }
@Override protected Resource decodeDataBuffer(DataBuffer dataBuffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { byte[] bytes = new byte[dataBuffer.readableByteCount()]; dataBuffer.read(bytes); DataBufferUtils.release(dataBuffer); if (logger.isDebugEnabled()) { logger.debug(Hints.getLogPrefix(hints) + "Read " + bytes.length + " bytes"); } Class<?> clazz = elementType.toClass(); if (clazz == InputStreamResource.class) { return new InputStreamResource(new ByteArrayInputStream(bytes)); } else if (Resource.class.isAssignableFrom(clazz)) { return new ByteArrayResource(bytes); } else { throw new IllegalStateException("Unsupported resource class: " + clazz); } }
@Test public void testInputStreamResource() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertEquals(resource, new InputStreamResource(is)); }
@Test public void testInputStreamResourceWithDescription() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is, "my description"); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new InputStreamResource(is)); }
@Test(expected = BeanDefinitionStoreException.class) public void withOpenInputStream() { SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml")); new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource); }
@Test public void withOpenInputStreamAndExplicitValidationMode() { SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry(); Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml")); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_DTD); reader.loadBeanDefinitions(resource); testBeanDefinitions(registry); }
public InputStreamPart(String name, InputStream inputStream) { super(name, new InputStreamResource(inputStream)); } }
/** * @param stream Input stream containing Spring XML configuration. * @return Context. * @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; }
/** * 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. * @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); } }
@Test //SPR-16754 public void disableRangeSupportForStreamingResponses() throws Exception { InputStream is = new ByteArrayInputStream("Content".getBytes(StandardCharsets.UTF_8)); InputStreamResource resource = new InputStreamResource(is, "test"); ResponseEntity<Resource> returnValue = ResponseEntity.ok(resource); servletRequest.addHeader("Range", "bytes=0-5"); given(resourceMessageConverter.canWrite(any(), eq(null))).willReturn(true); given(resourceMessageConverter.canWrite(any(), eq(APPLICATION_OCTET_STREAM))).willReturn(true); processor.handleReturnValue(returnValue, returnTypeResponseEntityResource, mavContainer, webRequest); then(resourceMessageConverter).should(times(1)).write( any(InputStreamResource.class), eq(APPLICATION_OCTET_STREAM), any(HttpOutputMessage.class)); assertEquals(200, servletResponse.getStatus()); assertThat(servletResponse.getHeader(HttpHeaders.ACCEPT_RANGES), Matchers.isEmptyOrNullString()); }
public static ProcessEngineConfiguration parseProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName) { Resource springResource = new InputStreamResource(inputStream); return parseProcessEngineConfiguration(springResource, beanName); }
public static ProcessEngineConfiguration parseProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName) { Resource springResource = new InputStreamResource(inputStream); return parseProcessEngineConfiguration(springResource, beanName); }
static InputStreamResource thisClassAsResource() { return new InputStreamResource( ParserTestUtil.class.getResourceAsStream(ParserTestUtil.class.getSimpleName() + ".class")); }
private ApplicationContext bootStrap(String configProperty) throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(new ClassPathResource("org/springframework/integration/jdbc/config/stored-proc-invalid-configs.properties")); pfb.afterPropertiesSet(); Properties prop = pfb.getObject(); StringBuilder buffer = new StringBuilder(); buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); ac.refresh(); return ac; }
private ApplicationContext bootStrap(String configProperty) throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/chain-elements-config.properties")); pfb.afterPropertiesSet(); Properties prop = pfb.getObject(); StringBuilder buffer = new StringBuilder(); buffer.append(prop.getProperty("xmlheaders")).append(prop.getProperty(configProperty)).append(prop.getProperty("xmlfooter")); ByteArrayInputStream stream = new ByteArrayInputStream(buffer.toString().getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); ac.refresh(); return ac; }
private ApplicationContext bootStrap(String configProperty) { ByteArrayInputStream stream = new ByteArrayInputStream(configProperty.getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); ac.refresh(); return ac; }
@Test(expected = BeanDefinitionStoreException.class) public void testNoMappingElement() { ByteArrayInputStream stream = new ByteArrayInputStream(routerConfigNoMaping.getBytes()); GenericApplicationContext ac = new GenericApplicationContext(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); reader.loadBeanDefinitions(new InputStreamResource(stream)); }