Search in sources :

Example 1 with FileSystemResource

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");
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

Example 2 with FileSystemResource

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);
}
Also used : FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URISyntaxException(java.net.URISyntaxException) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) URI(java.net.URI)

Example 3 with FileSystemResource

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));
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource)

Example 4 with FileSystemResource

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;
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Properties(java.util.Properties)

Example 5 with FileSystemResource

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());
}
Also used : FileSystemResource(org.springframework.core.io.FileSystemResource) Test(org.junit.Test)

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