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
}
}
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;
}
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();
}
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();
}
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;
}
Aggregations