Example usage for org.springframework.core.io Resource getInputStream

List of usage examples for org.springframework.core.io Resource getInputStream

Introduction

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

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream for the content of an underlying resource.

Usage

From source file:com.otterca.persistence.dao.KeyStoreConfiguration.java

/**
 * Get keystore containing certificates used in DAO unit tests.
 * //from ww  w.jav  a2  s  .  c  om
 * @return
 * @throws KeyStoreException
 * @throws CertificateException
 * @throws NoSuchAlgorithmException
 * @throws IOException
 */
@Bean
public synchronized KeyStore getKeyStore()
        throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {

    if (keyStore == null) {
        keyStore = KeyStore.getInstance(bundle.getString("keystore.type"));
        InputStream is = null;
        try {
            Resource resource = new ClassPathResource(bundle.getString("keystore.location"));
            is = resource.getInputStream();
            if (masterkey.containsKey("master.password")) {
                BasicTextEncryptor encryptor = new BasicTextEncryptor();
                encryptor.setPassword(masterkey.getString("master.password"));
                keyStore.load(is, encryptor.decrypt(bundle.getString("keystore.password")).toCharArray());
            } else {
                keyStore.load(is, null);
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
    return keyStore;
}

From source file:org.springextensions.db4o.io.ResourceStorage.java

/**
 * @param config//from w  w  w.  ja  va 2  s .  c  o  m
 * @param pageSize
 * @return
 */
@Override
protected Bin produceBin(BinConfiguration config, int pageSize) {
    try {
        Resource resource = resourceLoader.getResource(config.uri());
        byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
        final Bin newStorage = new PagingMemoryBin(pageSize, config.initialLength());
        newStorage.write(0, bytes, bytes.length);
        return newStorage;
    } catch (Exception e) {
        throw new Db4oIOException(e.getMessage());
    }
}

From source file:cn.kane.osgi.controller.test.DataPreparor.java

private String parseSqlIn(Resource resource) throws IOException {
    InputStream is = null;//from  w w  w  . ja  v  a  2  s.  c  om
    try {
        is = resource.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));

        StringWriter sw = new StringWriter();
        BufferedWriter writer = new BufferedWriter(sw);

        for (int c = reader.read(); c != -1; c = reader.read()) {
            writer.write(c);
        }
        writer.flush();
        return sw.toString();

    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:de.ingrid.iplug.opensearch.converter.IngridRSSConverterTest.java

public final void testProcessResultFromEuropeana() {
    try {/*from  w w w  . j ava  2s .c  o m*/
        Resource resource = new ClassPathResource(XML_INPUT_FILE_EUROPEANA);
        IngridHits hits = ingridConverter.processResult("bla", resource.getInputStream(), null);
        assertTrue(hits.getHits().length > 0);

    } catch (Exception e) {
        e.printStackTrace();
        fail("Test failed.");
    }
}

From source file:kr.co.skysoft.framework.dbms.ibatis.FwSqlMapClientFactoryBean.java

protected SqlMapClient buildSqlMapClient(Resource[] configLocations, Resource[] mappingLocations,
        Properties properties) throws IOException {

    if (ObjectUtils.isEmpty(configLocations)) {
        throw new IllegalArgumentException("At least 1 'configLocation' entry is required");
    }//from  w w w.  j a v  a  2s.com

    SqlMapClient client = null;
    FwSqlMapConfigParser configParser = new FwSqlMapConfigParser();
    for (Resource configLocation : configLocations) {
        InputStream is = configLocation.getInputStream();
        try {
            client = configParser.parse(is, properties);
        } catch (RuntimeException ex) {
            //SqlMap? ?  ???? ?   ? ?  ?? 
            logger.error("##### Failed to parse config resource: " + configLocation, ex);
        }
    }

    if (mappingLocations != null) {
        SqlMapParser mapParser = SqlMapParserFactory.createSqlMapParser(configParser);
        for (Resource mappingLocation : mappingLocations) {
            try {
                mapParser.parse(mappingLocation.getInputStream());
            } catch (NodeletException ex) {
                throw new NestedIOException("Failed to parse mapping resource: " + mappingLocation, ex);
            }
        }
    }

    return client;
}

From source file:org.geomajas.gwt.server.mvc.GwtResourceControllerTest.java

@Test
public void testResourceInClassPath() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletContext context = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setPathInfo("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    GwtResourceController resourceController = new GwtResourceController();
    resourceController.setServletContext(context);
    resourceController.getResource(request, response);
    Resource resource = new ClassPathResource("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    Assert.assertArrayEquals(IOUtils.toByteArray(resource.getInputStream()), response.getContentAsByteArray());
}

From source file:com.saysth.commons.quartz.ResourceLoaderClassLoadHelper.java

public InputStream getResourceAsStream(String name) {
    Resource resource = this.resourceLoader.getResource(name);
    try {//from w  w w.ja  v  a 2 s.  co  m
        return resource.getInputStream();
    } catch (FileNotFoundException ex) {
        return null;
    } catch (IOException ex) {
        logger.warn("Could not load " + resource);
        return null;
    }
}

From source file:org.geomajas.gwt.server.mvc.GwtResourceControllerTest.java

@Test
public void testResourceInContext() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletContext context = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setServletPath("/org");
    request.setPathInfo("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();
    GwtResourceController resourceController = new GwtResourceController();
    resourceController.setServletContext(context);
    resourceController.getResource(request, response);
    Resource resource = new ClassPathResource("/org/geomajas/gwt/server/mvc/geomajas_logo.png");
    Assert.assertArrayEquals(IOUtils.toByteArray(resource.getInputStream()), response.getContentAsByteArray());
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.provider.ResourcePropertiesProvider.java

/** @throws IOException on error */
public ResourcePropertiesProvider(final Resource resource) throws IOException {
    Validate.notNull(resource);/*www  .j  ava 2  s  .  com*/

    properties = new Properties();
    final InputStream is = resource.getInputStream();

    try {
        properties.load(is);
    } finally {
        is.close();
    }
}

From source file:com.epam.ta.reportportal.ws.MultipartRequestTest.java

@Test
public void testPageableLast() throws Exception {
    Resource multipartFile = new ClassPathResource(DEMO_FILE_NAME);
    MockMultipartFile mockMultipartFile = new MockMultipartFile(DEMO_FILE_NAME, multipartFile.getInputStream());

    this.mvcMock//w  ww  .ja v a  2  s .c o m
            .perform(fileUpload(PROJECT_BASE_URL + "/log").file(mockMultipartFile).secure(true)
                    .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
            .andExpect(status().is(400));

}