Search in sources :

Example 6 with FileSystemNotFoundException

use of java.nio.file.FileSystemNotFoundException in project ballerina by ballerina-lang.

the class BallerinaDocUtils method copyResources.

/**
 * Find a given resource and copy its content recursively to a given target path.
 * @param resource name of the resource
 * @param targetPath target directory path as a string.
 * @throws IOException Failure to load the resources.
 */
public static void copyResources(String resource, String targetPath) throws IOException {
    URI uri = null;
    try {
        // load the resource from the Class path
        uri = BallerinaDocUtils.class.getClassLoader().getResource(resource).toURI();
    } catch (URISyntaxException e) {
        throw new IOException("Failed to load resources: " + e.getMessage(), e);
    }
    Path source;
    try {
        source = Paths.get(uri);
    } catch (FileSystemNotFoundException e) {
        // this means the resource is in a jar file, hence we have to create a new File system for the jar
        Map<String, String> env = new HashMap<>();
        env.put("create", "true");
        FileSystems.newFileSystem(uri, env);
        source = Paths.get(uri);
    }
    Path target = Paths.get(targetPath, resource);
    Files.walkFileTree(source, new RecursiveFileVisitor(source, target));
}
Also used : Path(java.nio.file.Path) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with FileSystemNotFoundException

use of java.nio.file.FileSystemNotFoundException in project jimfs by google.

the class JimfsFileSystemCloseTest method testIsNotAvailableFromProvider.

@Test
public void testIsNotAvailableFromProvider() throws IOException {
    URI uri = fs.getUri();
    assertEquals(fs, FileSystems.getFileSystem(uri));
    fs.close();
    try {
        FileSystems.getFileSystem(uri);
        fail();
    } catch (FileSystemNotFoundException expected) {
    }
}
Also used : FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URI(java.net.URI) Test(org.junit.Test)

Example 8 with FileSystemNotFoundException

use of java.nio.file.FileSystemNotFoundException in project j2objc by google.

the class FileSystemNotFoundExceptionTest method test_constructor_empty.

public void test_constructor_empty() {
    FileSystemNotFoundException exception = new FileSystemNotFoundException();
    assertEquals(null, exception.getMessage());
}
Also used : FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException)

Example 9 with FileSystemNotFoundException

use of java.nio.file.FileSystemNotFoundException in project j2objc by google.

the class FileSystemNotFoundExceptionTest method test_constructor$String.

public void test_constructor$String() {
    String message = "message";
    FileSystemNotFoundException exception = new FileSystemNotFoundException(message);
    assertEquals(message, exception.getMessage());
}
Also used : FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException)

Example 10 with FileSystemNotFoundException

use of java.nio.file.FileSystemNotFoundException in project mycore by MyCoRe-Org.

the class MCRPaths method getPath.

static Path getPath(String scheme, String owner, String path) {
    URI uri;
    try {
        uri = getURI(scheme, owner, path);
        LogManager.getLogger(MCRPaths.class).debug("Generated path URI:{}", uri);
    } catch (URISyntaxException e) {
        throw new InvalidPathException(path, "URI syntax error (" + e.getMessage() + ") for path");
    }
    try {
        return Paths.get(uri);
    } catch (FileSystemNotFoundException e) {
        for (FileSystemProvider provider : webAppProvider) {
            if (provider.getScheme().equals(uri.getScheme())) {
                return provider.getPath(uri);
            }
        }
        throw e;
    }
}
Also used : FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) FileSystemProvider(java.nio.file.spi.FileSystemProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)20 IOException (java.io.IOException)11 Path (java.nio.file.Path)11 URI (java.net.URI)9 URISyntaxException (java.net.URISyntaxException)9 FileSystem (java.nio.file.FileSystem)5 File (java.io.File)4 URL (java.net.URL)4 HashMap (java.util.HashMap)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 Vulnerability (com.blackducksoftware.integration.fortify.batch.model.Vulnerability)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 CharSource (com.google.common.io.CharSource)1 Var (com.google.errorprone.annotations.Var)1