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;
}
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"))));
}
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();
}
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();
}
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();
}
Aggregations