Search in sources :

Example 6 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project spring-framework by spring-projects.

the class PathMatchingResourcePatternResolver method doFindMatchingFileSystemResources.

/**
	 * Find all resources in the file system that match the given location pattern
	 * via the Ant-style PathMatcher.
	 * @param rootDir the root directory in the file system
	 * @param subPattern the sub pattern to match (below the root directory)
	 * @return a mutable Set of matching Resource instances
	 * @throws IOException in case of I/O errors
	 * @see #retrieveMatchingFiles
	 * @see org.springframework.util.PathMatcher
	 */
protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Looking for matching resources in directory tree [" + rootDir.getPath() + "]");
    }
    Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
    Set<Resource> result = new LinkedHashSet<>(matchingFiles.size());
    for (File file : matchingFiles) {
        result.add(new FileSystemResource(file));
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UrlResource(org.springframework.core.io.UrlResource) VfsResource(org.springframework.core.io.VfsResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResource(org.springframework.core.io.FileSystemResource) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 7 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project spring-framework by spring-projects.

the class CollectionToCollectionConverterTests method differentImpls.

@Test
public void differentImpls() throws Exception {
    List<Resource> resources = new ArrayList<>();
    resources.add(new ClassPathResource("test"));
    resources.add(new FileSystemResource("test"));
    resources.add(new TestResource());
    TypeDescriptor sourceType = TypeDescriptor.forObject(resources);
    assertSame(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 8 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project spring-framework by spring-projects.

the class GzipResourceResolverTests method createGzFile.

private static void createGzFile(String filePath) throws IOException {
    Resource location = new ClassPathResource("test/", GzipResourceResolverTests.class);
    Resource fileResource = new FileSystemResource(location.createRelative(filePath).getFile());
    Path gzFilePath = Paths.get(fileResource.getFile().getAbsolutePath() + ".gz");
    Files.deleteIfExists(gzFilePath);
    File gzFile = Files.createFile(gzFilePath).toFile();
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile));
    FileCopyUtils.copy(fileResource.getInputStream(), out);
    gzFile.deleteOnExit();
}
Also used : Path(java.nio.file.Path) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 9 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project spring-framework by spring-projects.

the class GzipResourceResolverTests method createGzFile.

private static void createGzFile(String filePath) throws IOException {
    Resource location = new ClassPathResource("test/", GzipResourceResolverTests.class);
    Resource fileResource = new FileSystemResource(location.createRelative(filePath).getFile());
    Path gzFilePath = Paths.get(fileResource.getFile().getAbsolutePath() + ".gz");
    Files.deleteIfExists(gzFilePath);
    File gzFile = Files.createFile(gzFilePath).toFile();
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFile));
    FileCopyUtils.copy(fileResource.getInputStream(), out);
    gzFile.deleteOnExit();
}
Also used : Path(java.nio.file.Path) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 10 with FileSystemResource

use of org.springframework.core.io.FileSystemResource in project cas by apereo.

the class GoogleAccountsServiceResponseBuilder method createGoogleAppsPrivateKey.

/**
     * Create the private key.
     *
     * @throws Exception if key creation ran into an error
     */
protected void createGoogleAppsPrivateKey() throws Exception {
    if (!isValidConfiguration()) {
        LOGGER.debug("Google Apps private key bean will not be created, because it's not configured");
        return;
    }
    final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
    if (this.privateKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
        bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
    } else if (this.privateKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
        bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
    } else {
        bean.setLocation(new FileSystemResource(this.privateKeyLocation));
    }
    bean.setAlgorithm(this.keyAlgorithm);
    LOGGER.debug("Loading Google Apps private key from [{}] with key algorithm [{}]", bean.getLocation(), bean.getAlgorithm());
    bean.afterPropertiesSet();
    LOGGER.debug("Creating Google Apps private key instance via [{}]", this.privateKeyLocation);
    this.privateKey = bean.getObject();
}
Also used : PrivateKeyFactoryBean(org.apereo.cas.util.crypto.PrivateKeyFactoryBean) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

FileSystemResource (org.springframework.core.io.FileSystemResource)128 File (java.io.File)66 Test (org.junit.Test)41 Resource (org.springframework.core.io.Resource)35 Before (org.junit.Before)21 ClassPathResource (org.springframework.core.io.ClassPathResource)13 IOException (java.io.IOException)11 FileWriter (java.io.FileWriter)10 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)8 FileOutputStream (java.io.FileOutputStream)7 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 InputStreamResource (org.springframework.core.io.InputStreamResource)7 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 DefaultDataCollectionConfigDao (org.opennms.netmgt.config.DefaultDataCollectionConfigDao)6 FilesystemResourceStorageDao (org.opennms.netmgt.dao.support.FilesystemResourceStorageDao)5 FileReader (java.io.FileReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4 Ehcache (net.sf.ehcache.Ehcache)4