Java Code Examples for org.springframework.core.io.FileSystemResource#getFile()

The following examples show how to use org.springframework.core.io.FileSystemResource#getFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourcesFileSource.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private static FileSource[] toSources(Resource[] resources) {
	FileSource[] sources = new FileSource[resources.length];
	for (int i = 0; i < resources.length; i++) {
		Resource resource = resources[i];
		if (resource instanceof ClassPathResource) {
			ClassPathResource classes = (ClassPathResource) resource;
			sources[i] = new ClasspathFileSource(classes.getPath());
		}
		else if (resource instanceof FileSystemResource) {
			FileSystemResource files = (FileSystemResource) resource;
			sources[i] = new SingleRootFileSource(files.getFile());
		}
		else if (resource instanceof UrlResource) {
			sources[i] = fileOrFallbackToClasspath(resource);
		}
		else {
			throw new IllegalArgumentException(
					"Unsupported resource type for file source: "
							+ resource.getClass());
		}
	}
	return sources;
}
 
Example 2
Source File: RestFileManager.java    From sdk-rest with MIT License 5 votes vote down vote up
public void deleteTempResume(MultiValueMap<String, Object> multiValueMap) {
    // clean up file
    FileSystemResource fileSystemResource = (FileSystemResource) multiValueMap.getFirst(formFileName);

    File file = fileSystemResource.getFile();

    if (!file.delete()) {
        log.info("Unable to delete temp resume " + file.getAbsolutePath());
    }
}