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:com.wavemaker.commons.util.ConversionUtils.java

public static List<Resource> convertToResourceList(List<File> files) {
    List<Resource> resources = new ArrayList<Resource>();
    for (File file : files) {
        String path = file.getAbsolutePath();
        if (file.isDirectory() && !path.endsWith("/")) {
            path += "/";
        }//from   w  w w. j a  v a 2  s .c o  m
        resources.add(new FileSystemResource(path));
    }
    return resources;
}

From source file:config.ResourceUtils.java

/**
 * Checks if a resource with the given relative path exists on the file
 * system./*from w ww . ja  v  a 2s . c o m*/
 *
 * @param relativePath the relative path of the resource
 * @return the is existing boolean
 */
public static boolean isExistingFile(String relativePath) {
    boolean isExistingResource = Boolean.FALSE;
    Resource resource = new FileSystemResource(relativePath);
    if (resource.exists()) {
        isExistingResource = true;
    }

    return isExistingResource;
}

From source file:org.dd4t.core.util.IOUtils.java

public static String convertFileToString(String filePath) {
    FileSystemResource resource = new FileSystemResource(filePath);
    File file = resource.getFile();
    byte[] buffer = new byte[(int) file.length()];
    try {//from w w  w. j  a v a  2  s.c o  m
        resource.getInputStream().read(buffer);
        resource.getInputStream().close();
        return new String(buffer);
    } catch (IOException e) {
        return null;
    }
}

From source file:org.cloudfoundry.identity.api.BootstrapTests.java

@Test
public void testRootContext() throws Exception {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext(
            new FileSystemResource("src/main/webapp/WEB-INF/spring-servlet.xml"));
    context.close();//from   w w  w  . j  a v  a  2s  .c o m
}

From source file:org.camelcookbook.transactions.utils.EmbeddedDataSourceFactory.java

public static JdbcDataSource getJdbcDataSource(String initScriptLocation) {
    Validate.notEmpty(initScriptLocation, "initScriptLocation is empty");

    String mavenRelativePath = "src/main/resources/" + initScriptLocation;
    String mavenRootRelativePath = "camel-cookbook-transactions/" + mavenRelativePath;

    // check that we can load the init script
    FileLocator locator = new FileLocator().with(initScriptLocation).with(mavenRelativePath)
            .with(mavenRootRelativePath);
    File file = locator.find();/*from w  w  w  . j a v a  2s .com*/
    Validate.notNull(file, locator.getErrorMessage());
    FileSystemResource script = new FileSystemResource(file);

    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    DataSourceInitializer.initializeDataSource(dataSource, script);

    return dataSource;
}

From source file:co.paralleluniverse.galaxy.Server.java

/**
 * Starts the galaxy server./*from  w  w  w  .j  a  va 2  s. co  m*/
 * @param configFile The path to the xml (spring) configuration file {@code null} null for default.
 * @param propertiesFile The name of the properties file containing the grid's properties.
 * You may, of course use Spring's {@code <context:property-placeholder location="classpath:com/foo/bar.properties"/>} but this parameter is helpful when you want to use the same xml configuration
 * with different properties for different instances.
 */
public static void start(String configFile, String propertiesFile) {
    final ApplicationContext context = SpringContainerHelper.createContext("co.paralleluniverse.galaxy",
            configFile != null ? new FileSystemResource(configFile) : new ClassPathResource("galaxy.xml"),
            propertiesFile != null ? new FileSystemResource(propertiesFile) : null, null);
    MainMemory memory = context.getBean("memory", MainMemory.class);
    ((AbstractCluster) memory.getCluster()).goOnline();
}

From source file:com.example.PathTests.java

@Test
public void test() throws Exception {
    ClassPathResource classPath = new ClassPathResource("");
    System.err.println(classPath.getURL().toString());
    System.err.println(Paths.get(new FileSystemResource(new FileSystemResource("src/main/resources").getURL()
            .toURI().toString().substring("file:".length())).getFile().toURI()).isAbsolute());
}

From source file:org.my.spring.batch.java.config.demo.readers.ProductReader.java

@Autowired
public ProductReader(@Value("#{jobParameters[inputFile]}") String inputFile) {

    setResource(new FileSystemResource(inputFile));

    DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
    tokenizer.setNames(new String[] { "description", "price", "purchaseDate" });
    tokenizer.setDelimiter(DelimitedLineTokenizer.DELIMITER_TAB);

    BeanWrapperFieldSetMapper<Product> mapper = new BeanWrapperFieldSetMapper<>();
    mapper.setTargetType(Product.class);

    DefaultLineMapper<Product> defaultLineMapper = new DefaultLineMapper<>();

    defaultLineMapper.setLineTokenizer(tokenizer);
    defaultLineMapper.setFieldSetMapper(mapper);

    setLineMapper(defaultLineMapper);//  www .  j a  va  2s .  c om
}

From source file:org.my.sandbox.ProductReader.java

@Autowired
public void setInputFile(@Value("#{jobParameters[inputFile]}") String inputFile) {
    setResource(new FileSystemResource(inputFile));
}

From source file:io.gravitee.management.war.utils.PropertiesLoader.java

public Properties load() {
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();

    String yamlConfiguration = System.getProperty(GRAVITEE_CONFIGURATION);
    Resource yamlResource = new FileSystemResource(yamlConfiguration);

    yaml.setResources(yamlResource);//from   w ww . j a  v a  2 s.  c  om
    Properties properties = yaml.getObject();

    return properties;
}