Example usage for org.springframework.core.io InputStreamResource InputStreamResource

List of usage examples for org.springframework.core.io InputStreamResource InputStreamResource

Introduction

In this page you can find the example usage for org.springframework.core.io InputStreamResource InputStreamResource.

Prototype

public InputStreamResource(InputStream inputStream) 

Source Link

Document

Create a new InputStreamResource.

Usage

From source file:test.gov.nih.nci.logging.api.persistence.TestSpringLocationSessionFactoryBean.java

/**
 * @param args/*w w w .jav a 2s.  c o m*/
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    java.io.InputStream in = FileLoader.getInstance().getFileAsStream("commons-logging.properties");
    Resource resource = new InputStreamResource(in);
    System.out.println(resource.exists());

    LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    String mappingResources[] = { "gov/nih/nci/logging/api/domain/LogMessage.hbm.xml",
            "gov/nih/nci/logging/api/domain/ObjectAttribute.hbm.xml" };
    localSessionFactoryBean.setMappingResources(mappingResources);
    BasicDataSource ds = setDataSourceProperties();
    localSessionFactoryBean.setDataSource(ds);
    localSessionFactoryBean.setHibernateProperties(getJDBCProperties());

    try {
        localSessionFactoryBean.afterPropertiesSet();
    } catch (HibernateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SessionFactory sf = (SessionFactory) localSessionFactoryBean.getObject();
    //SessionFactory sessionFactory = (SessionFactory) ObjectFactory.getObject(ObjectFactory.HibernateSessionFactory);
}

From source file:ch.tatool.app.service.export.DataImportTest.java

public static void main(String[] args) {
    // get the httpentity containing the data
    HttpEntity httpEntity = getHttpEntity();
    // Create a httpclient instance
    DefaultHttpClient httpclient = new DefaultHttpClient();
    // setup a POST call
    HttpGet httpGet = new HttpGet(serverUrl);

    try {/*from   www.j  a va 2s  .c om*/
        HttpResponse response = httpclient.execute(httpGet);
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            System.out.println("Unable to download data: " + response.getStatusLine().getReasonPhrase());
            System.out.println(response.getStatusLine().getStatusCode());
        } else {
            // all ok
            HttpEntity enty = response.getEntity();
            InputStream is = enty.getContent();

            XmlBeanFactory beanFactory = null;
            try {

                beanFactory = new XmlBeanFactory(new InputStreamResource(is));

            } catch (BeansException be) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("Unable to load module configuration", be);
            }

            // check whether we have the mandatory beans (rootElement)
            if (!beanFactory.containsBean("rootElement")) {
                // TODO: inform user that training configuration is broken
                throw new RuntimeException("No rootElement bean found in the module configuration file");
            }

            // fetch the rootElement
            Node rootElement = (Node) beanFactory.getBean("rootElement");

            System.out.println(rootElement.getId());

        }
    } catch (IOException ioe) {

    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

From source file:eu.scape_project.archiventory.identifiers.DroidIdentificationTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    arcFilesMap = ArcFilesTestMap.getInstance().getMap();
    InputStream odtTestFileStream = DroidIdentification.class
            .getResourceAsStream("DROID_SignatureFile_V67.xml");
    Resource r = new InputStreamResource(odtTestFileStream);
    id = new DroidIdentification(r);
}

From source file:org.wso2.carbon.springservices.GenericApplicationContextUtil.java

public static GenericApplicationContext getSpringApplicationContext(InputStream applicationContxtInStream,
        String springBeansFilePath) throws AxisFault {
    GenericApplicationContext appContext = new GenericApplicationContext();

    XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
    xbdr.setValidating(false);//from www . ja  v a  2s .  co m
    xbdr.loadBeanDefinitions(new InputStreamResource(applicationContxtInStream));
    appContext.refresh();
    return appContext;
}

From source file:org.bambooframework.dao.impl.cfg.BeansConfigurationHelper.java

public static DaoEngineConfigurationImpl parseProcessEngineConfigurationFromInputStream(InputStream inputStream,
        String beanName) {//from  w w  w .j  a va2s .co m
    Resource springResource = new InputStreamResource(inputStream);
    return parseDaoEngineConfiguration(springResource, beanName);
}

From source file:de.perdian.commons.lang.conversion.impl.converters.TestResourceToStreamConverter.java

@Test
public void testConvert() {
    InputStream inputStream = Mockito.mock(InputStream.class);
    ResourceToStreamConverter converter = new ResourceToStreamConverter();
    Assert.assertSame(inputStream, converter.convert(new InputStreamResource(inputStream)));
}

From source file:org.jtheque.i18n.I18NResourceFactory.java

/**
 * Construct a I18NResource from the path using the class (with the class loader) to load it.
 *
 * @param classz The class to get the class loader.
 * @param path   The resource path./*from  w w w.j  a v a  2s .  c o m*/
 *
 * @return The I18NResource corresponding to the given resource.
 */
public static I18NResource fromResource(Class<?> classz, String path) {
    Resource resource = new InputStreamResource(classz.getClassLoader().getResourceAsStream(path));

    return new I18NResourceImpl(path.substring(path.lastIndexOf('/')), resource);
}

From source file:org.activiti.crystalball.simulator.impl.cfg.BeansConfigurationHelper.java

public static SimulationEngineConfiguration parseSimulationEngineConfigurationFromInputStream(
        InputStream inputStream, String beanName) {
    Resource springResource = new InputStreamResource(inputStream);
    return parseSimulationEngineConfiguration(springResource, beanName);
}

From source file:th.co.geniustree.intenship.advisor.controller.IndexController.java

@RequestMapping(value = "/teacher/{id}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getFileTeacher(@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  w w .  j a  v a  2 s.co m
}

From source file:com.kylinolap.rest.security.PasswordPlaceholderConfigurer.java

public PasswordPlaceholderConfigurer() {
    Resource[] resources = new Resource[1];
    resources[0] = new InputStreamResource(KylinConfig.getKylinPropertiesAsInputSteam());
    this.setLocations(resources);
}