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:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java

@Test
public void testUnmatchingBaseDir() throws Exception {
    exception.expect(ZipFilesException.class);
    String aTargetFilename = "target/Z5-input.zip";
    ZipFilesTasklet aTasklet = new ZipFilesTasklet();
    aTasklet.setSourceBaseDirectory(new FileSystemResource("target/"));
    FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory();
    aSourceFactory.setPattern("file:src/test/resources/testFiles/input.csv");
    aTasklet.setSourceFactory(aSourceFactory);
    ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory();
    aDestinationFactory.setExpression(aTargetFilename);
    aTasklet.setDestinationFactory(aDestinationFactory);

    assertEquals(RepeatStatus.FINISHED, aTasklet.execute(null, null));
}

From source file:com.myee.tarot.core.config.RuntimePropertyPlaceholderConfigurer.java

protected Resource createOverrideResource() throws IOException {
    String path = System.getProperty(PROPERTY_OVERRIDE);
    return StringUtils.isBlank(path) ? null : new FileSystemResource(path);
}

From source file:com.indeed.imhotep.web.ImhotepMetadataCache.java

private void loadSuggestions(File indexDir, DatasetMetadata datasetMetadata) {
    final File suggestionsXml = new File(indexDir, "suggestions.xml");
    if (!suggestionsXml.exists()) {
        return;/*  w  ww . ja va  2 s.c  o  m*/
    }
    @SuppressWarnings("unchecked")
    final Map<String, String> suggestions = (Map<String, String>) new XmlBeanFactory(
            new FileSystemResource(suggestionsXml)).getBean("suggestionMap");
    if (suggestions != null) {
        for (Map.Entry<String, String> suggestion : suggestions.entrySet()) {
            datasetMetadata.addFieldMetricDescription(suggestion.getKey(), suggestion.getValue(), null, false,
                    true, false);
        }
    }
}

From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java

public static Resource staticGetWaveMakerHome() {

    Resource ret = null;//from  w  ww  .  j a v a  2 s.  co m

    String env = System.getProperty(WMHOME_PROP_KEY, null);
    if (env != null && 0 != env.length()) {
        ret = new FileSystemResource(env);
    }

    if (ret == null) {
        String pref = ConfigurationStore.getPreference(LocalStudioConfiguration.class, WMHOME_KEY, null);
        if (pref != null && 0 != pref.length()) {
            pref = pref.endsWith("/") ? pref : pref + "/";
            ret = new FileSystemResource(pref);
        }
    }

    // we couldn't find a test value, a property, or a preference, so use
    // a default
    if (ret == null) {
        System.out.println("INFO: Using default WaveMaker Home folder");
        ret = getDefaultWaveMakerHome();
    }

    if (!ret.exists()) {
        try {
            ret.getFile().mkdir();
        } catch (IOException ex) {
            throw new WMRuntimeException(ex);
        }
    }

    return ret;
}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobConfigurationService.java

/**
 * Interface Method Implementation./*from ww  w.java2s.  c om*/
 * @see org.trpr.platform.batch.spi.spring.admin.JobConfigurationService#getJobConfig(String)
 */
@Override
public Resource getJobConfig(String jobName) {
    if (this.getJobConfigURI(jobName) == null) {
        return null;
    }
    return new FileSystemResource(new File(getJobConfigURI(jobName)));
}

From source file:cz.zcu.kiv.eeg.mobile.base.ui.scenario.ScenarioAddActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    //obtaining file selected in FileChooserActivity
    case (Values.SELECT_FILE_FLAG): {
        if (resultCode == Activity.RESULT_OK) {
            selectedFile = data.getExtras().getString(Values.FILE_PATH);
            selectedFileLength = data.getExtras().getLong(Values.FILE_LENGTH);
            TextView selectedFileView = (TextView) findViewById(R.id.fchooserSelectedFile);
            EditText mimeView = (EditText) findViewById(R.id.scenario_mime_value);
            TextView fileSizeView = (TextView) findViewById(R.id.scenario_file_size_value);

            FileSystemResource file = new FileSystemResource(selectedFile);
            selectedFileView.setText(file.getFilename());
            mimeView.setText(FileUtils.getMimeType(selectedFile));

            String fileSize = FileUtils.getFileSize(file.getFile().length());
            fileSizeView.setText(fileSize);
            Toast.makeText(this, selectedFile, Toast.LENGTH_SHORT).show();
        }/*from  w  w  w .j a  va2s  .com*/
        break;
    }
    }
}

From source file:com.apdplat.platform.compass.APDPlatLocalCompassBean.java

public void afterPropertiesSet() throws Exception {
    CompassConfiguration config = this.config;
    if (config == null) {
        config = newConfiguration();/*from   w w  w . ja v a  2  s. c  o  m*/
    }

    if (classLoader != null) {
        config.setClassLoader(getClassLoader());
    }

    if (this.configLocation != null) {
        config.configure(this.configLocation.getURL());
    }

    if (this.configLocations != null) {
        for (Resource configLocation1 : configLocations) {
            config.configure(configLocation1.getURL());
        }
    }

    if (this.mappingScan != null) {
        config.addScan(this.mappingScan);
    }

    if (this.compassSettings != null) {
        config.getSettings().addSettings(this.compassSettings);
    }

    if (this.settings != null) {
        config.getSettings().addSettings(this.settings);
    }

    if (resourceLocations != null) {
        for (Resource resourceLocation : resourceLocations) {
            config.addInputStream(resourceLocation.getInputStream(), resourceLocation.getFilename());
        }
    }

    if (resourceJarLocations != null && !"".equals(resourceJarLocations.trim())) {
        log.info("apdplatcompass2");
        log.info("compass resourceJarLocations:" + resourceJarLocations);
        String[] jars = resourceJarLocations.split(",");
        for (String jar : jars) {
            try {
                FileSystemResource resource = new FileSystemResource(FileUtils.getAbsolutePath(jar));
                config.addJar(resource.getFile());
                log.info("compass resourceJarLocations  find:" + jar);
            } catch (Exception e) {
                log.info("compass resourceJarLocations not exists:" + jar);
            }
        }
    }

    if (classMappings != null) {
        for (String classMapping : classMappings) {
            config.addClass(ClassUtils.forName(classMapping, getClassLoader()));
        }
    }

    if (resourceDirectoryLocations != null && !"".equals(resourceDirectoryLocations.trim())) {
        log.info("apdplatcompass3");
        log.info("compass resourceDirectoryLocations:" + resourceDirectoryLocations);
        String[] dirs = resourceDirectoryLocations.split(",");
        for (String dir : dirs) {
            ClassPathResource resource = new ClassPathResource(dir);
            try {
                File file = resource.getFile();
                if (!file.isDirectory()) {
                    log.info("Resource directory location [" + dir + "] does not denote a directory");
                } else {
                    config.addDirectory(file);
                }
                log.info("compass resourceDirectoryLocations find:" + dir);
            } catch (Exception e) {
                log.info("compass resourceDirectoryLocations not exists:" + dir);
            }
        }
    }

    if (mappingResolvers != null) {
        for (InputStreamMappingResolver mappingResolver : mappingResolvers) {
            config.addMappingResover(mappingResolver);
        }
    }

    if (dataSource != null) {
        ExternalDataSourceProvider.setDataSource(dataSource);
        if (config.getSettings().getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS) == null) {
            config.getSettings().setSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.CLASS,
                    ExternalDataSourceProvider.class.getName());
        }
    }

    String compassTransactionFactory = config.getSettings().getSetting(CompassEnvironment.Transaction.FACTORY);
    if (compassTransactionFactory == null && transactionManager != null) {
        // if the transaciton manager is set and a transcation factory is not set, default to the SpringSync one.
        config.getSettings().setSetting(CompassEnvironment.Transaction.FACTORY,
                SpringSyncTransactionFactory.class.getName());
    }
    if (compassTransactionFactory != null
            && compassTransactionFactory.equals(SpringSyncTransactionFactory.class.getName())) {
        if (transactionManager == null) {
            throw new IllegalArgumentException(
                    "When using SpringSyncTransactionFactory the transactionManager property must be set");
        }
    }
    SpringSyncTransactionFactory.setTransactionManager(transactionManager);

    if (convertersByName != null) {
        for (Map.Entry<String, Converter> entry : convertersByName.entrySet()) {
            config.registerConverter(entry.getKey(), entry.getValue());
        }
    }
    if (config.getSettings().getSetting(CompassEnvironment.NAME) == null) {
        config.getSettings().setSetting(CompassEnvironment.NAME, beanName);
    }

    if (config.getSettings().getSetting(CompassEnvironment.CONNECTION) == null && connection != null) {
        config.getSettings().setSetting(CompassEnvironment.CONNECTION, connection.getFile().getAbsolutePath());
    }

    if (applicationContext != null) {
        String[] names = applicationContext.getBeanNamesForType(PropertyPlaceholderConfigurer.class);
        for (String name : names) {
            try {
                PropertyPlaceholderConfigurer propConfigurer = (PropertyPlaceholderConfigurer) applicationContext
                        .getBean(name);
                Method method = findMethod(propConfigurer.getClass(), "mergeProperties");
                method.setAccessible(true);
                Properties props = (Properties) method.invoke(propConfigurer);
                method = findMethod(propConfigurer.getClass(), "convertProperties", Properties.class);
                method.setAccessible(true);
                method.invoke(propConfigurer, props);
                method = findMethod(propConfigurer.getClass(), "parseStringValue", String.class,
                        Properties.class, Set.class);
                method.setAccessible(true);
                String nullValue = null;
                try {
                    Field field = propConfigurer.getClass().getDeclaredField("nullValue");
                    field.setAccessible(true);
                    nullValue = (String) field.get(propConfigurer);
                } catch (NoSuchFieldException e) {
                    // no field (old spring version)
                }
                for (Map.Entry entry : config.getSettings().getProperties().entrySet()) {
                    String key = (String) entry.getKey();
                    String value = (String) entry.getValue();
                    value = (String) method.invoke(propConfigurer, value, props, new HashSet());
                    config.getSettings().setSetting(key, value.equals(nullValue) ? null : value);
                }
            } catch (Exception e) {
                log.debug("Failed to apply property placeholder defined in bean [" + name + "]", e);
            }
        }
    }

    if (postProcessor != null) {
        postProcessor.process(config);
    }
    this.compass = newCompass(config);
    this.compass = (Compass) Proxy.newProxyInstance(SpringCompassInvocationHandler.class.getClassLoader(),
            new Class[] { InternalCompass.class }, new SpringCompassInvocationHandler(this.compass));
}

From source file:edu.harvard.i2b2.crc.loader.util.CRCLoaderUtil.java

/**
 * Load application property file into memory
 *//* ww  w. jav a 2 s.c o  m*/
private String getPropertyValue(String propertyName) throws I2B2Exception {
    if (appProperties == null) {
        // read application directory property file
        loadProperties = ServiceLocator.getProperties(APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        // read application directory property
        String appDir = loadProperties.getProperty(APPLICATIONDIR_PROPERTIES);
        if (appDir == null) {
            throw new I2B2Exception("Could not find " + APPLICATIONDIR_PROPERTIES + "from "
                    + APPLICATION_DIRECTORY_PROPERTIES_FILENAME);
        }
        String appPropertyFile = appDir + "/" + APPLICATION_PROPERTIES_FILENAME;
        try {
            FileSystemResource fileSystemResource = new FileSystemResource(appPropertyFile);
            PropertiesFactoryBean pfb = new PropertiesFactoryBean();
            pfb.setLocation(fileSystemResource);
            pfb.afterPropertiesSet();
            appProperties = (Properties) pfb.getObject();
        } catch (IOException e) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
        if (appProperties == null) {
            throw new I2B2Exception("Application property file(" + appPropertyFile
                    + ") missing entries or not loaded properly");
        }
    }

    String propertyValue = appProperties.getProperty(propertyName);

    if ((propertyValue != null) && (propertyValue.trim().length() > 0)) {
        ;
    } else {
        throw new I2B2Exception("Application property file(" + APPLICATION_PROPERTIES_FILENAME + ") missing "
                + propertyName + " entry");
    }

    return propertyValue;
}

From source file:cn.org.once.cstack.initializer.CloudUnitApplicationContext.java

/**
 * Get Resources to load for CloudUnit Context.
 *
 * @param profileProperties The filename of the profile properties.
 * @return An array of Resource.//ww w .  j a v a  2s .  com
 * The array will have at least the profileProperties given by parameter, and eventually a custom
 * configuration file if found in the {@code $HOME/.cloudunit/} repertory.
 */
private static Resource[] getResources(String profileProperties) {
    final File customFile = new File(System.getProperty("user.home") + "/.cloudunit/configuration.properties");
    Resource[] resources = null;

    if (customFile.exists()) {
        logger.warn("Custom file configuration found ! : {}", customFile.getAbsolutePath());

        resources = new Resource[] { new ClassPathResource(profileProperties),
                new FileSystemResource(customFile) };
    } else {
        logger.warn(customFile.getAbsolutePath() + " is missing. Needed for production !");
        resources = new Resource[] { new ClassPathResource(profileProperties), };
    }
    return resources;
}