Search in sources :

Example 1 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project spring-boot by spring-projects.

the class AbstractJsonMarshalTester method read.

/**
	 * Return {@link ObjectContent} from reading from the specified input stream.
	 * @param inputStream the source input stream
	 * @return the {@link ObjectContent}
	 * @throws IOException on read error
	 */
public ObjectContent<T> read(InputStream inputStream) throws IOException {
    verify();
    Assert.notNull(inputStream, "InputStream must not be null");
    return read(new InputStreamResource(inputStream));
}
Also used : InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 2 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project spring-framework by spring-projects.

the class XmlBeanDefinitionReaderTests method withOpenInputStreamAndExplicitValidationMode.

@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);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 3 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project spring-framework by spring-projects.

the class XmlBeanDefinitionReaderTests method withOpenInputStream.

@Test(expected = BeanDefinitionStoreException.class)
public void withOpenInputStream() {
    SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    Resource resource = new InputStreamResource(getClass().getResourceAsStream("test.xml"));
    new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 4 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class ConfigurationTestUtils method getSpringResourceForResourceWithReplacements.

public static Resource getSpringResourceForResourceWithReplacements(final Object obj, final String resource, final String[]... replacements) throws IOException {
    try {
        String config = getConfigForResourceWithReplacements(obj, resource, replacements);
        File tmp = File.createTempFile("testConfigFile", ".xml");
        tmp.deleteOnExit();
        FileWriter fw = new FileWriter(tmp);
        fw.write(config);
        fw.close();
        return new FileSystemResource(tmp);
    } catch (final Throwable t) {
        return new InputStreamResource(getInputStreamForResourceWithReplacements(obj, resource, replacements));
    }
}
Also used : FileWriter(java.io.FileWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 5 with InputStreamResource

use of org.springframework.core.io.InputStreamResource in project opennms by OpenNMS.

the class AbstractJaxbConfigDaoTest method testAfterPropertiesSetWithGoodConfigFile.

public void testAfterPropertiesSetWithGoodConfigFile() throws Exception {
    TestJaxbConfigDao dao = new TestJaxbConfigDao();
    InputStream in = ConfigurationTestUtils.getInputStreamForConfigFile("jdbc-datacollection-config.xml");
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
    assertNotNull("jdbc data collection should not be null", dao.getDataCollectionConfig());
}
Also used : InputStream(java.io.InputStream) InputStreamResource(org.springframework.core.io.InputStreamResource)

Aggregations

InputStreamResource (org.springframework.core.io.InputStreamResource)32 Test (org.junit.Test)12 InputStream (java.io.InputStream)11 Resource (org.springframework.core.io.Resource)10 FileSystemResource (org.springframework.core.io.FileSystemResource)8 File (java.io.File)6 DatacollectionConfig (org.opennms.netmgt.config.datacollection.DatacollectionConfig)6 SnmpCollection (org.opennms.netmgt.config.datacollection.SnmpCollection)6 FileInputStream (java.io.FileInputStream)4 ClassPathResource (org.springframework.core.io.ClassPathResource)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 X509Certificate (java.security.cert.X509Certificate)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)2 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)2 DefaultStatisticsDaemonConfigDao (org.opennms.netmgt.dao.jaxb.DefaultStatisticsDaemonConfigDao)2 BeansException (org.springframework.beans.BeansException)2 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)2