List of usage examples for java.nio.file Path iterator
@Override
default Iterator<Path> iterator()
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt"); Iterator<Path> it = path.iterator(); while (it.hasNext()) { System.out.println(it.next()); }//from w ww. j a v a 2s .c o m }
From source file:com.facebook.buck.util.Escaper.java
/** * Escapes forward slashes in a Path as a String that is safe to consume with other tools (such * as gcc). On Unix systems, this is equivalent to {@link java.nio.file.Path Path.toString()}. * @param path the Path to escape/*from www . ja v a 2 s . co m*/ * @return the escaped Path */ public static String escapePathForCIncludeString(Path path) { if (File.separatorChar != '\\') { return path.toString(); } StringBuilder result = new StringBuilder(); if (path.startsWith(File.separator)) { result.append("\\\\"); } for (Iterator<Path> iterator = path.iterator(); iterator.hasNext();) { result.append(iterator.next()); if (iterator.hasNext()) { result.append("\\\\"); } } if (path.getNameCount() > 0 && path.endsWith(File.separator)) { result.append("\\\\"); } return result.toString(); }
From source file:de.tiqsolutions.hdfs.HadoopFileSystemPath.java
@Override public boolean startsWith(Path other) { return startsWith(this.iterator(), other.iterator()); }
From source file:nl.mpi.lamus.filesystem.implementation.LamusWorkspaceDirectoryHandler.java
/** * @see WorkspaceDirectoryHandler#ensurePathIsAllowed(String) *//*from w w w. j a va 2s . c o m*/ @Override public void ensurePathIsAllowed(String path) throws DisallowedPathException { Path pathToCheck = Paths.get("", path); Iterator<Path> pathIterator = pathToCheck.iterator(); while (pathIterator.hasNext()) { Path currentPathItem = pathIterator.next(); String nameToMatch = currentPathItem.getFileName().toString(); for (String regex : disallowedFolderNamesWorkspace) { if (Pattern.matches(regex, nameToMatch)) { String message = "The path [" + path + "] contains a disallowed file/folder name (" + nameToMatch + ")"; throw new DisallowedPathException(path, message); } } } }
From source file:org.roda.core.common.monitor.TransferredResourcesScanner.java
public static TransferredResource instantiateTransferredResource(Path resourcePath, Path basePath) { Path relativeToBase = basePath.relativize(resourcePath); TransferredResource tr = new TransferredResource(); tr.setFile(!FSUtils.isDirectory(resourcePath)); tr.setFullPath(resourcePath.toString()); String id = relativeToBase.toString(); tr.setId(id);// w ww . ja v a 2s . c o m tr.setUUID(IdUtils.getTransferredResourceUUID(relativeToBase)); tr.setName(resourcePath.getFileName().toString()); tr.setRelativePath(relativeToBase.toString()); if (relativeToBase.getParent() != null) { String parentId = relativeToBase.getParent().toString(); tr.setParentId(parentId); tr.setParentUUID(IdUtils.createUUID(parentId)); } List<String> ancestors = new ArrayList<>(); StringBuilder temp = new StringBuilder(); Iterator<Path> pathIterator = relativeToBase.iterator(); while (pathIterator.hasNext()) { temp.append(pathIterator.next().toString()); ancestors.add(temp.toString()); temp.append("/"); } ancestors.remove(ancestors.size() - 1); tr.setAncestorsPaths(ancestors); return tr; }
From source file:org.roda_project.commons_ip.utils.Utils.java
public static List<String> getFileRelativeFolders(Path basePath, Path filePath) { List<String> res = new ArrayList<>(); Path relativize = basePath.relativize(filePath).getParent(); if (relativize != null) { Iterator<Path> iterator = relativize.iterator(); while (iterator.hasNext()) { res.add(iterator.next().toString()); }/*w ww .j a v a 2 s . c o m*/ } return res; }