use of org.springframework.core.io.FileSystemResource in project cas by apereo.
the class FileTrustStoreSslSocketFactoryTests method verifyTrustStoreNotFound.
@Test
public void verifyTrustStoreNotFound() throws Exception {
this.thrown.expect(RuntimeException.class);
new FileTrustStoreSslSocketFactory(new FileSystemResource("test.jks"), "changeit");
}
use of org.springframework.core.io.FileSystemResource in project ratpack by ratpack.
the class RatpackProperties method resourceToPath.
static Path resourceToPath(URL resource) {
Objects.requireNonNull(resource, "Resource URL cannot be null");
URI uri;
try {
uri = resource.toURI();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Could not extract URI", e);
}
String scheme = uri.getScheme();
if (scheme.equals("file")) {
String path = uri.toString().substring("file:".length());
if (path.contains("//")) {
path = StringUtils.cleanPath(path.replace("//", ""));
}
return Paths.get(new FileSystemResource(path).getFile().toURI());
}
if (!scheme.equals("jar")) {
throw new IllegalArgumentException("Cannot convert to Path: " + uri);
}
String s = uri.toString();
int separator = s.indexOf("!/");
URI fileURI = URI.create(s.substring(0, separator) + "!/");
try {
FileSystems.getFileSystem(fileURI);
} catch (FileSystemNotFoundException e) {
try {
FileSystems.newFileSystem(fileURI, Collections.singletonMap("create", "true"));
} catch (IOException e1) {
throw new IllegalArgumentException("Cannot convert to Path: " + uri);
}
}
return Paths.get(fileURI);
}
use of org.springframework.core.io.FileSystemResource in project spring-boot by spring-projects.
the class AbstractJsonMarshalTester method read.
/**
* Return {@link ObjectContent} from reading from the specified file.
* @param file the source file
* @return the {@link ObjectContent}
* @throws IOException on read error
*/
public ObjectContent<T> read(File file) throws IOException {
verify();
Assert.notNull(file, "File must not be null");
return read(new FileSystemResource(file));
}
use of org.springframework.core.io.FileSystemResource in project spring-boot by spring-projects.
the class Verify method verifyBuildInfo.
public static Properties verifyBuildInfo(File file, String group, String artifact, String name, String version) throws IOException {
FileSystemResource resource = new FileSystemResource(file);
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
assertThat(properties.get("build.group")).isEqualTo(group);
assertThat(properties.get("build.artifact")).isEqualTo(artifact);
assertThat(properties.get("build.name")).isEqualTo(name);
assertThat(properties.get("build.version")).isEqualTo(version);
return properties;
}
use of org.springframework.core.io.FileSystemResource in project spring-framework by spring-projects.
the class YamlMapFactoryBeanTests method testSetBarfOnResourceNotFound.
@Test(expected = IllegalStateException.class)
public void testSetBarfOnResourceNotFound() throws Exception {
this.factory.setResources(new FileSystemResource("non-exsitent-file.yml"));
assertEquals(0, this.factory.getObject().size());
}
Aggregations