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

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

Introduction

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

Prototype

public FileSystemResource(Path filePath) 

Source Link

Document

Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File .

Usage

From source file:org.opennms.ng.services.polloutagesconfig.PollOutagesConfigFactory.java

/**
 * Private constructor/*  w  ww  .j  a v  a  2  s . c  o  m*/
 *
 * @throws java.io.IOException                       Thrown if the specified config file cannot be read
 * @throws org.exolab.castor.xml.MarshalException    Thrown if the file does not conform to the schema.
 * @throws org.exolab.castor.xml.ValidationException Thrown if the contents do not match the required schema.
 */
public PollOutagesConfigFactory(final String configFile) {
    setConfigResource(new FileSystemResource(configFile));
}

From source file:org.opennms.ng.services.eventconfig.EventsArchiverConfigFactory.java

/**
 * Private constructor//from w  w w .j  av  a 2  s . c  o  m
 * 
 * @exception java.io.IOException
 *                Thrown if the specified config file cannot be read
 * @exception org.exolab.castor.xml.MarshalException
 *                Thrown if the file does not conform to the schema.
 * @exception org.exolab.castor.xml.ValidationException
 *                Thrown if the contents do not match the required schema.
 */
private EventsArchiverConfigFactory(String configFile)
        throws IOException, MarshalException, ValidationException {
    m_config = CastorUtils.unmarshal(EventsArchiverConfiguration.class, new FileSystemResource(configFile));
}

From source file:com.inkubator.hrm.batch.PayTempOvertimeUploadReader.java

private void initializationExcelReader(String filePath) {

    //read a Excel file
    Resource resource = new FileSystemResource(filePath);

    try {// ww  w.  ja v a2 s  .  co m
        //mapped to an object
        BeanPropertyRowMapper<PayTempOvertimeFileModel> rowMapper = new BeanPropertyRowMapper<>();
        rowMapper.setTargetType(PayTempOvertimeFileModel.class);
        rowMapper.afterPropertiesSet();

        //initial poiItemReader
        excelFileReader = new PoiItemReader<>();
        excelFileReader.setResource(resource);
        excelFileReader.setLinesToSkip(1);
        excelFileReader.setRowMapper(rowMapper);
        excelFileReader.afterPropertiesSet();
        excelFileReader.open(new ExecutionContext());

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.mybatis.caches.ignite.IgniteCacheAdapter.java

/**
 * Constructor./*w w w  .  j a v a 2  s. c  o m*/
 *
 * @param id
 *          Cache id.
 */
@SuppressWarnings("unchecked")
public IgniteCacheAdapter(String id) {
    if (id == null) {
        throw new IllegalArgumentException("Cache instances require an ID");
    }

    CacheConfiguration<Object, Object> cacheCfg = null;

    try {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

        new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new FileSystemResource(new File(CFG_PATH)));

        cacheCfg = (CacheConfiguration<Object, Object>) factory.getBean("templateCacheCfg");

        cacheCfg.setEvictionPolicy(null);
        cacheCfg.setCacheLoaderFactory(null);
        cacheCfg.setCacheWriterFactory(null);

        // overrides template cache name with the specified id.
        cacheCfg.setName(id);
    } catch (NoSuchBeanDefinitionException | BeanDefinitionStoreException e) {
        // initializes the default cache.
        log.warn("Initializing the default cache. Consider properly configuring '" + CFG_PATH + "' instead.");
        log.trace("" + e);

        cacheCfg = new CacheConfiguration<>(id);
    }

    cache = ignite.getOrCreateCache(cacheCfg);

    this.id = id;
}

From source file:nl.knaw.dans.common.lang.spring.FileBasedPropertyPlaceholderConfigurer.java

public FileBasedPropertyPlaceholderConfigurer(final String resourcePath) throws FileNotFoundException {
    final List<File> locationsToTry = new LinkedList<File>();
    final String filename = System.getProperty("user.name") + ".properties";
    locationsToTry.add(new File(resourcePath, filename));
    locationsToTry.add(new File(resourcePath, DEFAULT_RESOURCE_PATH + "/" + filename));
    locationsToTry.add(new File(resourcePath, DEFAULT_PROPERTIES_FILE));
    locationsToTry.add(new File(resourcePath, DEFAULT_RESOURCE_PATH + "/" + DEFAULT_PROPERTIES_FILE));
    for (final File file : locationsToTry) {
        if (file.exists()) {
            logger.info("Found application properties at " + file.getAbsolutePath());
            setLocation(new FileSystemResource(file));
            return;
        }/*from  w  w w . j  a v  a  2  s.  c  om*/
    }
    throw new FileNotFoundException(
            String.format("No properties file found; tried: %s", locationsToTry.toString()));
}

From source file:test.org.tradex.camel.TestCaseAppContextBuilder.java

/**
 * Builds an application context reading the file from the passed path
 * @param path The path of the app context xml
 * @return the built app context/*from  w w  w . j av a 2s .com*/
 */
public static GenericXmlApplicationContext buildFor(String path) {
    if (path == null)
        throw new IllegalArgumentException("Passed path was null", new Throwable());
    File springXml = new File(path);
    if (!springXml.canRead()) {
        throw new RuntimeException("Failed to read Spring XML file at [" + springXml + "]", new Throwable());
    }
    try {
        return service(new GenericXmlApplicationContext(
                new FileSystemResource[] { new FileSystemResource(springXml.getAbsoluteFile()) }));
    } catch (Throwable t) {
        LOG.fatal("Failed to boot app context", t);
        throw new RuntimeException("Failed to boot app context", t);
    }
}

From source file:org.cloudfoundry.reconfiguration.util.StandardCloudUtilsTest.java

@Test
public void isUsingCloudServicesInvalidCloudService() throws IOException {
    when(this.applicationContext.getResources("classpath*:/META-INF/cloud/cloud-services"))
            .thenReturn(new Resource[] { new FileSystemResource("src/test/resources/invalid-cloud-services") });

    assertFalse(this.cloudUtils.isUsingCloudServices(this.applicationContext));

    verify(this.applicationContext, times(0)).getBeanNamesForType(any(Class.class));
}

From source file:org.jboss.examples.spring.batch.BatchConfiguration.java

@Bean
public FlatFileItemWriter<AggregateItem<Trade>> writer() {
    FlatFileItemWriter rc = new FlatFileItemWriter();
    rc.setLineAggregator(new PassThroughLineAggregator());
    rc.setResource(new FileSystemResource("./target/multistep.txt"));
    return rc;// w w  w . j  a va 2s .  c  o  m
}

From source file:gov.nih.nci.integration.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from file system//from ww w .j a  v  a 2s  .  c  o  m
 * 
 * @param properties - properties to merge
 * @param environmentVariable - environment variable (for ex : user.home, app.home etc)
 * @param pathToScan - the detailed path to scan
 */
private static void fillPropertiesFromFileSystem(Properties properties, final String environmentVariable,
        String pathToScan) {
    if (StringUtils.isBlank(System.getProperty(environmentVariable))) {
        LOG.info(String.format("%s is not set. So skipping property lookup from %s", environmentVariable,
                environmentVariable));
    } else {
        final String detailedEnvironmentPath = StringUtils.replace(pathToScan, environmentVariable,
                System.getProperty(environmentVariable));
        fillProperties(new FileSystemResource(detailedEnvironmentPath), properties);
    }
}