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

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

Introduction

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

Prototype

public DefaultResourceLoader() 

Source Link

Document

Create a new DefaultResourceLoader.

Usage

From source file:org.paxml.util.PaxmlUtils.java

public static Resource readResource(String resUri) {
    return new DefaultResourceLoader().getResource(resUri);
}

From source file:com.vdenotaris.spring.boot.security.saml.web.config.WebSecurityConfig.java

@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource("classpath:/saml/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}

From source file:com.ctrip.infosec.rule.executor.RulesExecutorServiceTest.java

@Test
public void testBuildResult() throws IOException {

    String jsonStr = IOUtils/*  w w w . j a va2s .co m*/
            .toString(new DefaultResourceLoader().getResource("classpath:finalResult.json").getInputStream());
    RiskFact fact = JSON.parseObject(jsonStr, RiskFact.class);

    RulesExecutorService rulesExecutorService = new RulesExecutorService();

    rulesExecutorService.buidFinalResult(fact, false);

    System.out.println(JSON.toJSONString(fact));

}

From source file:com.edgenius.core.util.FileUtil.java

/**
 * Wrapper of Spring DefaultResourceLoader. 
 * The location must start with "classpath:" or "file://", otherwise, this method
 * may throw file not found exception.//w  w  w.jav  a 2  s  .c  om
 * Important: The file must be in file system. This means it won't work if it is in jar or zip file etc.
 * Please getFileInputStream() to get input stream directly if they are in jar or zip
 *
 * @param location
 * @return
 * @throws IOException 
 */
public static File getFile(String location) throws IOException {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource res = loader.getResource(location);
    try {
        return res.getFile();
    } catch (IOException e) {
        throw (e);
    }
}

From source file:eu.dnetlib.maven.plugin.properties.WritePredefinedProjectProperties.java

/**
 * Provides input stream.//from  w w  w.  j  a va 2 s.com
 * @param location
 * @return input stream
 * @throws IOException
 */
protected InputStream getInputStream(String location) throws IOException {
    File file = new File(location);
    if (file.exists()) {
        return new FileInputStream(location);
    }
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource(location);
    return resource.getInputStream();
}

From source file:com.haulmont.cuba.testsupport.TestContainer.java

protected void initAppProperties() {
    final Properties properties = new Properties();

    List<String> locations = getAppPropertiesFiles();
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    for (String location : locations) {
        Resource resource = resourceLoader.getResource(location);
        if (resource.exists()) {
            InputStream stream = null;
            try {
                stream = resource.getInputStream();
                properties.load(stream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                IOUtils.closeQuietly(stream);
            }/*from ww  w.j a  va 2  s  . com*/
        } else {
            log.warn("Resource " + location + " not found, ignore it");
        }
    }

    StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() {
        @Override
        public String lookup(String key) {
            String subst = properties.getProperty(key);
            return subst != null ? subst : System.getProperty(key);
        }
    });
    for (Object key : properties.keySet()) {
        String value = substitutor.replace(properties.getProperty((String) key));
        appProperties.put((String) key, value);
    }

    File dir;
    dir = new File(appProperties.get("cuba.confDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.logDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.tempDir"));
    dir.mkdirs();
    dir = new File(appProperties.get("cuba.dataDir"));
    dir.mkdirs();
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

/**
 * {@inheritDoc}/*from  w ww  .  j  a  v  a  2 s. c  o m*/
 */
@Before
@Override
public void setup() throws Exception {
    super.setup();

    // Re-point archives
    this.jobsLocationsProperties.setArchives(this.temporaryFolder.newFolder().toURI().toString());

    this.schedulerJobName = UUID.randomUUID().toString();
    this.schedulerRunId = UUID.randomUUID().toString();
    this.metadata = GenieObjectMapper.getMapper().readTree("{\"" + SCHEDULER_JOB_NAME_KEY + "\":\""
            + this.schedulerJobName + "\", \"" + SCHEDULER_RUN_ID_KEY + "\":\"" + this.schedulerRunId + "\"}");

    this.resourceLoader = new DefaultResourceLoader();
    this.createAnApplication(APP1_ID, APP1_NAME);
    this.createAnApplication(APP2_ID, APP2_NAME);
    this.createAllClusters();
    this.createAllCommands();
    this.linkAllEntities();
}

From source file:com.edgenius.core.util.FileUtil.java

/**
 * /*from  ww  w .j a  va2 s.  c  o m*/
 * @param location
 * @return
 * @throws IOException 
 */
public static InputStream getFileInputStream(String location) throws IOException {
    //Don't user DefaultResourceLoader directly, as test it try to find host "c" if using method resource.getInputStream()
    // while location is "file://c:/var/test" etc.

    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource res = loader.getResource(location);
    if (ResourceUtils.isJarURL(res.getURL())) {
        //it is in jar file, we just assume it won't be changed in runtime, so below method is safe.
        try {
            return res.getInputStream();
        } catch (IOException e) {
            throw (e);
        }
    } else {
        //in Tomcat, the classLoader cache the input stream even using thread scope classloader, but it is still failed
        //if the reload in same thread. For example, DataRoot class save and reload in same thread when install.
        //So, we assume if the file is not inside jar file, we will always reload the file into a new InputStream from file system.

        //if it is not jar resource, then try to refresh the input stream by file system
        return new FileInputStream(res.getFile());
    }
}

From source file:com.naveen.demo.config.Saml2SSOConfig.java

@Bean
public KeyManager keyManager() {
    DefaultResourceLoader loader = new DefaultResourceLoader();
    Resource storeFile = loader.getResource("classpath:/encryption/samlKeystore.jks");
    String storePass = "nalle123";
    Map<String, String> passwords = new HashMap<String, String>();
    passwords.put("apollo", "nalle123");
    String defaultKey = "apollo";
    return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}