Search in sources :

Example 6 with InvalidPathException

use of java.nio.file.InvalidPathException in project jetty.project by eclipse.

the class FileSystemResourceTest method testAddDoubleSlash.

@Test
public void testAddDoubleSlash() throws Exception {
    Path dir = testdir.getPath().normalize().toRealPath();
    Files.createDirectories(dir);
    Path basePath = dir.resolve("base");
    FS.ensureDirExists(basePath);
    Path dirPath = basePath.resolve("aa");
    FS.ensureDirExists(dirPath);
    Path filePath = dirPath.resolve("foo.txt");
    Files.createFile(filePath);
    try (Resource base = newResource(basePath.toFile())) {
        assertThat("Exists: " + basePath, base.exists(), is(true));
        assertThat("Alias: " + basePath, base, hasNoAlias());
        Resource r = base.addPath("aa//foo.txt");
        assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa//foo.txt"));
        assertThat("isAlias()", r.isAlias(), is(true));
        assertThat("getAlias()", r.getAlias(), notNullValue());
        assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("aa/foo.txt"));
        assertThat("Exists: " + r, r.exists(), is(true));
    } catch (InvalidPathException e) {
    // Exception is acceptable
    }
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException) Test(org.junit.Test)

Example 7 with InvalidPathException

use of java.nio.file.InvalidPathException in project buck by facebook.

the class FileClassPathRunner method getClasspathFiles.

// @VisibileForTesting
@SuppressWarnings("PMD.EmptyCatchBlock")
static List<Path> getClasspathFiles(URL[] urls) {
    List<Path> paths = new LinkedList<>();
    for (URL url : urls) {
        if (!"file".equals(url.getProtocol())) {
            continue;
        }
        // Segment the path, looking for a section that starts with "@". If one is found, reconstruct
        // the rest of the path.
        // WARNING: While the classfile's path can contain directories that include "@", the path
        // cannot contain a directory that starts with "@".
        String path = url.getPath();
        int found, splitIndex = -1;
        if (path == null || path.length() == 0) {
            continue;
        } else if (path.charAt(0) == '@') {
            // path starts with '@'
            splitIndex = 1;
        } else if ((found = path.indexOf("/@")) >= 0) {
            // found first section that begins with '@'
            splitIndex = found + 2;
        }
        if (splitIndex > 0 && splitIndex < path.length()) {
            try {
                paths.add(Paths.get(path.substring(splitIndex)));
            } catch (InvalidPathException e) {
            // Carry on regardless
            }
        }
    }
    return paths;
}
Also used : Path(java.nio.file.Path) LinkedList(java.util.LinkedList) URL(java.net.URL) InvalidPathException(java.nio.file.InvalidPathException)

Example 8 with InvalidPathException

use of java.nio.file.InvalidPathException in project EnrichmentMapApp by BaderLab.

the class GSEAResolver method getRptResultsFile.

private static Optional<Path> getRptResultsFile(Path root, String fileName, Map<String, String> params) {
    // RPT files contain absolute paths from the machine where the GSEA analysis was run.
    // If the user moves the GSEA folder somewhere else then the paths won't resolve.
    // We can still attempt to find the files in the same folder where the RPT file is located.
    String label = params.get("param rpt_label");
    // Gsea or GseaPreranked
    String method = params.get("producer_class").split("\\p{Punct}")[2];
    String timestamp = params.get("producer_timestamp");
    String out_dir = params.get("param out");
    String job_dir_name = label + "." + method + "." + timestamp;
    // attempt to find the file using the path in the RPT file
    try {
        Path abs = Paths.get(out_dir, job_dir_name, fileName);
        if (Files.exists(abs)) {
            return Optional.of(abs);
        }
    } catch (InvalidPathException e) {
        e.printStackTrace();
    }
    try {
        // attempt to find the file under the folder containing the RPT file
        Path rel = root.resolve(fileName);
        if (Files.exists(rel)) {
            return Optional.of(rel);
        }
    } catch (InvalidPathException e) {
        e.printStackTrace();
    }
    return Optional.empty();
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Example 9 with InvalidPathException

use of java.nio.file.InvalidPathException in project EnrichmentMapApp by BaderLab.

the class GSEAResolver method getRptExpressionFile.

private static Optional<Path> getRptExpressionFile(Map<String, String> params) {
    // Gsea or GseaPreranked
    String method = params.get("producer_class").split("\\p{Punct}")[2];
    String data;
    if (method.equalsIgnoreCase("Gsea")) {
        data = params.get("param res");
    } else if (method.equalsIgnoreCase("GseaPreranked")) {
        data = params.get("param rnk");
        if (params.containsKey("param expressionMatrix")) {
            data = params.get("param expressionMatrix");
        }
    } else {
        return Optional.empty();
    }
    try {
        Path exprfile = Paths.get(data);
        if (Files.exists(exprfile))
            return Optional.of(exprfile);
    } catch (InvalidPathException e) {
        e.printStackTrace();
    }
    return Optional.empty();
}
Also used : Path(java.nio.file.Path) InvalidPathException(java.nio.file.InvalidPathException)

Example 10 with InvalidPathException

use of java.nio.file.InvalidPathException in project EnrichmentMapApp by BaderLab.

the class SwingUtil method validatePathTextField.

public static boolean validatePathTextField(JTextField textField, @Nullable Color validForeground, boolean optional) {
    Color fg = validForeground == null ? Color.BLACK : validForeground;
    boolean valid;
    try {
        String text = textField.getText();
        if (optional && Strings.isNullOrEmpty(text.trim())) {
            valid = true;
        } else {
            valid = Files.isReadable(Paths.get(text));
        }
    } catch (InvalidPathException e) {
        valid = false;
    }
    textField.setForeground(valid ? fg : Color.RED);
    return valid;
}
Also used : Color(java.awt.Color) InvalidPathException(java.nio.file.InvalidPathException)

Aggregations

InvalidPathException (java.nio.file.InvalidPathException)97 Path (java.nio.file.Path)53 IOException (java.io.IOException)26 URL (java.net.URL)14 File (java.io.File)13 MalformedURLException (java.net.MalformedURLException)12 Test (org.junit.Test)11 AlluxioURI (alluxio.AlluxioURI)7 Resource (org.springframework.core.io.Resource)7 Nullable (org.springframework.lang.Nullable)7 URI (java.net.URI)6 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5 URIStatus (alluxio.client.file.URIStatus)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 InputStream (java.io.InputStream)4 FileOutStream (alluxio.client.file.FileOutStream)3 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)3 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2