List of usage examples for java.nio.file Path isAbsolute
boolean isAbsolute();
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt"); System.out.println(path.isAbsolute()); }
From source file:Main.java
public static void main(String[] args) { Path path = FileSystems.getDefault().getPath("/home/docs/status.txt"); System.out.println(path.isAbsolute()); }
From source file:jsonbrowse.JsonBrowse.java
/** * @param args the command line arguments *//*from w w w .ja v a 2 s. com*/ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(JsonBrowse.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> String fileName; // Get name of JSON file Path jsonFilePath; if (args.length < 1) { JFileChooser fc = new JFileChooser(System.getProperty("user.dir")); fc.setDialogTitle("Select JSON file..."); fc.setFileFilter(new FileNameExtensionFilter("JSON files (*.json/*.txt)", "json", "txt")); if ((fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)) { jsonFilePath = fc.getSelectedFile().toPath().toAbsolutePath(); } else { return; } } else { Path path = Paths.get(args[0]); if (!path.isAbsolute()) jsonFilePath = Paths.get(System.getProperty("user.dir")).resolve(path); else jsonFilePath = path; } // Run app try { JsonBrowse app = new JsonBrowse(jsonFilePath); app.setVisible(true); } catch (FileNotFoundException ex) { System.out.println("Input file '" + jsonFilePath + "' not found."); System.exit(1); } catch (IOException ex) { System.out.println("Error reading from file '" + jsonFilePath + "'."); System.exit(1); } catch (InterruptedException ex) { Logger.getLogger(JsonBrowse.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.usc.goffish.gofs.tools.GoFSDeployGraph.java
@SuppressWarnings("deprecation") public static void main(String[] args) throws IOException { if (args.length < REQUIRED_ARGS) { PrintUsageAndQuit(null);/*from w ww .j av a 2s.c o m*/ } if (args.length == 1 && args[0].equals("-help")) { PrintUsageAndQuit(null); } // optional arguments boolean overwriteGraph = false; PartitionerMode partitionerMode = PartitionerMode.METIS; ComponentizerMode componentizerMode = ComponentizerMode.WCC; MapperMode mapperMode = MapperMode.ROUNDROBIN; PartitionedFileMode partitionedFileMode = PartitionedFileMode.DEFAULT; DistributerMode distributerMode = DistributerMode.SCP; int instancesGroupingSize = 1; int numSubgraphBins = -1; // optional sub arguments Path metisBinaryPath = null; String[] extraMetisOptions = null; Path partitioningPath = null; Path partitionedGMLFilePath = null; // parse optional arguments int i = 0; OptArgLoop: for (i = 0; i < args.length - REQUIRED_ARGS; i++) { switch (args[i]) { case "-overwriteGraph": overwriteGraph = true; break; case "-partitioner": i++; if (args[i].equals("stream")) { partitionerMode = PartitionerMode.STREAM; } else if (args[i].startsWith("metis")) { String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("metis")) { partitionerMode = PartitionerMode.METIS; if (subargs.length > 1) { try { metisBinaryPath = Paths.get(subargs[1]); if (!metisBinaryPath.isAbsolute()) { throw new InvalidPathException(metisBinaryPath.toString(), "metis binary path must be absolute"); } } catch (InvalidPathException e) { PrintUsageAndQuit("metis binary - " + e.getMessage()); } if (subargs.length > 2) { extraMetisOptions = parseSubArgs(' ', subargs[2]); } } } else { PrintUsageAndQuit(null); } } else if (args[i].startsWith("predefined")) { String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("predefined")) { partitionerMode = PartitionerMode.PREDEFINED; if (subargs.length < 2) { PrintUsageAndQuit(null); } try { partitioningPath = Paths.get(subargs[1]); } catch (InvalidPathException e) { PrintUsageAndQuit("partitioning file - " + e.getMessage()); } } else { PrintUsageAndQuit(null); } } else { PrintUsageAndQuit(null); } break; case "-intermediategml": if (args[i + 1].startsWith("save")) { i++; String[] subargs = parseSubArgs('=', args[i]); if (subargs[0].equals("save")) { if (subargs.length < 2) { PrintUsageAndQuit(null); } partitionedFileMode = PartitionedFileMode.SAVE; try { partitionedGMLFilePath = Paths.get(subargs[1]); } catch (InvalidPathException e) { PrintUsageAndQuit("partitioned gml file - " + e.getMessage()); } } } else { partitionedFileMode = PartitionedFileMode.READ; } break; case "-componentizer": i++; switch (args[i]) { case "single": componentizerMode = ComponentizerMode.SINGLE; break; case "wcc": componentizerMode = ComponentizerMode.WCC; break; default: PrintUsageAndQuit(null); } break; case "-distributer": i++; switch (args[i]) { case "scp": distributerMode = DistributerMode.SCP; break; case "write": distributerMode = DistributerMode.WRITE; break; default: PrintUsageAndQuit(null); } break; case "-mapper": i++; if (args[i].equalsIgnoreCase("roundrobin")) { mapperMode = MapperMode.ROUNDROBIN; } else { PrintUsageAndQuit(null); } break; case "-serializer:instancegroupingsize": i++; try { if (args[i].equalsIgnoreCase("ALL")) { instancesGroupingSize = Integer.MAX_VALUE; } else { instancesGroupingSize = Integer.parseInt(args[i]); if (instancesGroupingSize < 1) { PrintUsageAndQuit("Serialization instance grouping size must be greater than zero"); } } } catch (NumberFormatException e) { PrintUsageAndQuit("Serialization instance grouping size - " + e.getMessage()); } break; case "-serializer:numsubgraphbins": i++; try { numSubgraphBins = Integer.parseInt(args[i]); if (instancesGroupingSize < 1) { PrintUsageAndQuit("Serialization number of subgraph bins must be greater than zero"); } } catch (NumberFormatException e) { PrintUsageAndQuit("Serialization number of subgraph bins - " + e.getMessage()); } break; default: break OptArgLoop; } } if (args.length - i < REQUIRED_ARGS) { PrintUsageAndQuit(null); } // required arguments IInternalNameNode nameNode = null; Class<? extends IInternalNameNode> nameNodeType = null; URI nameNodeLocation = null; String graphId = null; int numPartitions = 0; Path gmlTemplatePath = null; List<Path> gmlInstancePaths = new LinkedList<>(); // parse required arguments try { nameNodeType = NameNodeProvider.loadNameNodeType(args[i]); i++; } catch (ReflectiveOperationException e) { PrintUsageAndQuit("name node type - " + e.getMessage()); } try { nameNodeLocation = new URI(args[i]); i++; } catch (URISyntaxException e) { PrintUsageAndQuit("name node location - " + e.getMessage()); } try { nameNode = NameNodeProvider.loadNameNode(nameNodeType, nameNodeLocation); } catch (ReflectiveOperationException e) { PrintUsageAndQuit("error loading name node - " + e.getMessage()); } graphId = args[i++]; try { numPartitions = Integer.parseInt(args[i]); i++; } catch (NumberFormatException e) { PrintUsageAndQuit("number of partitions - " + e.getMessage()); } Path gmlInputFile = null; try { gmlInputFile = Paths.get(args[i]); i++; } catch (InvalidPathException e) { PrintUsageAndQuit(e.getMessage()); } // finished parsing args if (i < args.length) { PrintUsageAndQuit("Unrecognized argument \"" + args[i] + "\""); } // ensure name node is available if (!nameNode.isAvailable()) { throw new IOException("Name node at " + nameNode.getURI() + " is not available"); } // ensure there are data nodes available Set<URI> dataNodes = nameNode.getDataNodes(); if (dataNodes == null || dataNodes.isEmpty()) { throw new IllegalArgumentException("name node does not have any data nodes available for deployment"); } // ensure graph id does not exist (unless to be overwritten) IntCollection partitions = nameNode.getPartitionDirectory().getPartitions(graphId); if (partitions != null) { if (!overwriteGraph) { throw new IllegalArgumentException( "graph id \"" + graphId + "\" already exists in name node partition directory"); } else { for (int partitionId : partitions) { nameNode.getPartitionDirectory().removePartitionMapping(graphId, partitionId); } } } IGraphLoader loader = null; IPartitioner partitioner = null; if (partitionedFileMode != PartitionedFileMode.READ) { XMLConfiguration configuration; try { configuration = new XMLConfiguration(gmlInputFile.toFile()); configuration.setDelimiterParsingDisabled(true); //read the template property gmlTemplatePath = Paths.get(configuration.getString("template")); //read the instance property for (Object instance : configuration.getList("instances.instance")) { gmlInstancePaths.add(Paths.get(instance.toString())); } } catch (ConfigurationException | InvalidPathException e) { PrintUsageAndQuit("gml input file - " + e.getMessage()); } // create loader loader = new GMLGraphLoader(gmlTemplatePath); // create partitioner switch (partitionerMode) { case METIS: if (metisBinaryPath == null) { partitioner = new MetisPartitioner(); } else { partitioner = new MetisPartitioner(metisBinaryPath, extraMetisOptions); } break; case STREAM: partitioner = new StreamPartitioner(new LDGObjectiveFunction()); break; case PREDEFINED: partitioner = new PredefinedPartitioner( MetisPartitioning.read(Files.newInputStream(partitioningPath))); break; default: PrintUsageAndQuit(null); } } // create componentizer IGraphComponentizer graphComponentizer = null; switch (componentizerMode) { case SINGLE: graphComponentizer = new SingleComponentizer(); break; case WCC: graphComponentizer = new WCCComponentizer(); break; default: PrintUsageAndQuit(null); } // create mapper IPartitionMapper partitionMapper = null; switch (mapperMode) { case ROUNDROBIN: partitionMapper = new RoundRobinPartitionMapper(nameNode.getDataNodes()); break; default: PrintUsageAndQuit(null); } // create serializer ISliceSerializer serializer = nameNode.getSerializer(); if (serializer == null) { throw new IOException("name node at " + nameNode.getURI() + " returned null serializer"); } // create distributer IPartitionDistributer partitionDistributer = null; switch (distributerMode) { case SCP: partitionDistributer = new SCPPartitionDistributer(serializer, instancesGroupingSize, numSubgraphBins); break; case WRITE: partitionDistributer = new DirectWritePartitionDistributer(serializer, instancesGroupingSize, numSubgraphBins); break; } GMLPartitionBuilder partitionBuilder = null; try { System.out.print("Executing command: DeployGraph"); for (String arg : args) { System.out.print(" " + arg); } System.out.println(); // perform deployment long time = System.currentTimeMillis(); switch (partitionedFileMode) { case DEFAULT: partitionBuilder = new GMLPartitionBuilder(graphComponentizer, gmlTemplatePath, gmlInstancePaths); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner, partitionBuilder, null, partitionMapper, partitionDistributer); break; case SAVE: //save partitioned gml files partitionBuilder = new GMLPartitionBuilder(partitionedGMLFilePath, graphComponentizer, gmlTemplatePath, gmlInstancePaths); //partitioned gml input file name format as graphid_numpartitions_paritioningtype_serializer String intermediateGMLInputFile = new StringBuffer().append(graphId).append("_") .append(numPartitions).append("_").append(partitionerMode.name().toLowerCase()).append("_") .append(serializer.getClass().getSimpleName().toLowerCase()).toString(); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner, partitionBuilder, intermediateGMLInputFile, partitionMapper, partitionDistributer); break; case READ: //read partitioned gml files partitionBuilder = new GMLPartitionBuilder(graphComponentizer); partitionBuilder.new XMLConfigurationBuilder(gmlInputFile.toFile().getAbsolutePath()) .readIntermediateGMLFile(); deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, partitionBuilder, partitionMapper, partitionDistributer); break; } System.out.println("finished [total " + (System.currentTimeMillis() - time) + "ms]"); } finally { if (partitionBuilder != null) partitionBuilder.close(); } }
From source file:org.fao.geonet.utils.FilePathChecker.java
/** * Checks that a file path is not absolute path and doesn't have .. characters, throwing an exception * in these cases./*from w ww.j av a 2 s. c o m*/ * * @param filePath * @throws Exception */ public static void verify(String filePath) throws BadParameterEx { if (StringUtils.isEmpty(filePath)) return; if (filePath.contains("..")) { throw new BadParameterEx("Invalid character found in path.", filePath); } Path path = Paths.get(filePath); if (path.isAbsolute() || filePath.startsWith("/") || filePath.startsWith("://", 1)) { throw new BadParameterEx("Invalid character found in path.", filePath); } }
From source file:heigit.ors.util.FileUtility.java
public static Boolean isAbsolutePath(String path) { Path path2 = Paths.get(path); return path2.isAbsolute(); }
From source file:org.sonar.java.AbstractJavaClasspath.java
private static Path resolvePath(Path baseDir, String fileName) { Path filePath = Paths.get(fileName); if (!filePath.isAbsolute()) { filePath = baseDir.resolve(fileName); }/*from w w w . j av a 2 s . co m*/ return filePath.normalize(); }
From source file:org.kie.workbench.common.services.backend.compiler.external339.AFConfigurationProcessor.java
static Path resolvePath(Path file, String workingDirectory) { return file == null ? null : (file.isAbsolute() ? file : (file.getFileName().startsWith(File.separator) ? file.toAbsolutePath() : (Paths.get(workingDirectory, file.getFileName().toString())))); }
From source file:ch.bender.evacuate.Helper.java
/** * Deletes a whole directory (recursively) * <p>/* www . ja va2s.c om*/ * @param aDir * a folder to be deleted (must not be null) * @throws IOException */ public static void deleteDirRecursive(Path aDir) throws IOException { if (aDir == null) { throw new IllegalArgumentException("aDir must not be null"); } if (Files.notExists(aDir)) { return; } if (!Files.isDirectory(aDir)) { throw new IllegalArgumentException("given aDir is not a directory"); } Files.walkFileTree(aDir, new SimpleFileVisitor<Path>() { /** * @see java.nio.file.SimpleFileVisitor#visitFileFailed(java.lang.Object, java.io.IOException) */ @Override public FileVisitResult visitFileFailed(Path aFile, IOException aExc) throws IOException { if ("System Volume Information".equals((aFile.getFileName().toString()))) { return FileVisitResult.SKIP_SUBTREE; } throw aExc; } /** * @see java.nio.file.SimpleFileVisitor#preVisitDirectory(java.lang.Object, java.nio.file.attribute.BasicFileAttributes) */ @Override public FileVisitResult preVisitDirectory(Path aFile, BasicFileAttributes aAttrs) throws IOException { if ("System Volume Information".equals((aFile.getFileName()))) { return FileVisitResult.SKIP_SUBTREE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (dir.isAbsolute() && dir.getRoot().equals(dir)) { myLog.debug("root cannot be deleted: " + dir.toString()); return FileVisitResult.CONTINUE; } Files.delete(dir); return FileVisitResult.CONTINUE; } }); }
From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.AFSettingsXmlConfigurationProcessor.java
static Path resolvePath(Path file, String workingDirectory) { if (file == null) { return null; } else if (file.isAbsolute()) { return file; } else if (file.getFileName().startsWith(File.separator)) { return file.toAbsolutePath(); } else {//w w w.j ava 2 s. co m return Paths.get(workingDirectory, file.getFileName().toString()); } }