@Override public Iterator<Path> iterator() { return delegate.iterator(); }
public static Iterator<Path> dirIterator(Path dir) { return dir.iterator(); }
@Override public Iterator<Path> iterator() { return path.iterator(); }
@Override public Iterator<Path> iterator() { return delegate.iterator(); }
@Override @Nonnull public Iterator<Path> iterator() { return new Iterator<Path>() { private final Iterator<java.nio.file.Path> wrappedIterator = nioPath.iterator(); @Override public void remove() { this.wrappedIterator.remove(); } @Override public boolean hasNext() { return this.wrappedIterator.hasNext(); } @Override @Nullable public Path next() { return makePathIfNotNull(this.wrappedIterator.next()); } }; }
private static List<String> pathToStringList(final Path file) { final List<String> xs = new ArrayList<>(16); final Iterator<Path> iter = file.iterator(); while (iter.hasNext()) { xs.add(iter.next().toString()); } return xs; }
private Path effectiveCamelContext(Path givenPath, Path defaultPath) { Path resultPath = givenPath; if (resultPath == null) { resultPath = defaultPath; } List<Path> pathElements = new ArrayList<>(); resultPath.iterator().forEachRemaining(pathElements::add); if (pathElements.size() < 2) { resultPath = Paths.get("camel", resultPath.toString()); } return resultPath.isAbsolute() ? resultPath : outpath.resolve(resultPath); } }
default Optional<Directory> getDirectory(Path path) { Directory currentDir = this; Iterator<Path> it = path.iterator(); while(it.hasNext() && currentDir != null) { currentDir = currentDir.getDirectories().get(it.next().toString()); } return Optional.ofNullable(currentDir); } }
Set<ConstraintViolation<Foo>> constraintViolations = ...; Path path = constraintViolations.iterator().next().getPropertyPath(); Iterator<Path.Node> nodeIterator = path.iterator(); Path.Node node = nodeIterator.next(); Bar bar = (Bar) node.as( PropertyNode.class ).getValue();
private void createZipEntries(ZipOutputStream zos, String filepath) throws IOException { Iterator<Path> elements = Paths.get(filepath).iterator(); StringBuilder sb = new StringBuilder(); while (elements.hasNext()) { Path path = elements.next(); String element = path.toString(); // If there are more elements to come this element is a directory // The "/" at the end tells the ZipEntry it is a folder if (elements.hasNext()) { element += "/"; } // Each entry needs the complete path, including previous created folders. zos.putNextEntry(new ZipEntry(sb + element)); sb.append(element); } }
@Override public Iterator<Path> iterator() { return fs.wrapIterator(zipPath.iterator()); }
@Nonnull @Override default Iterator<Path> iterator() {return wrapped().iterator();}
private static String parsePathWithWhiteSpace(Path path) { StringBuffer output = new StringBuffer(); output.append(path.getRoot()); Iterator<Path> pathIterator = path.iterator(); while (pathIterator.hasNext()) { output.append(System.getProperty("file.separator")); output.append(parsePathWithWhiteSpace(pathIterator.next().toString())); } return output.toString(); }
static FileResource getContentFileResource(Path template, Path contentDir, Directory root) { if (!template.startsWith(contentDir)) { throw new IllegalArgumentException(); } Path relativeContent = contentDir.relativize(template); Directory base = root; for (Iterator<Path> d = relativeContent.iterator(); d.hasNext();) { Path p = d.next(); if (d.hasNext()) { base = base.getDirectories().get(p.toString()); } else { return base.getFiles().get(p.toString()); } } throw new IllegalArgumentException("not found"); } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { StringBuilder path = new StringBuilder(); Iterator<Path> it = root.relativize(file).iterator(); while (it.hasNext()) { Path p = it.next(); boolean isDir = it.hasNext(); path.append(p.toString()); if (isDir) { path.append("/"); } String currentPath = path.toString(); if (added.contains(currentPath)) { continue; } ZipEntry entry = new ZipEntry(currentPath); out.putNextEntry(entry); if (!isDir) { Files.copy(file, out); } out.closeEntry(); added.add(currentPath); } return FileVisitResult.CONTINUE; } });
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) { // Top-level dir doesn't need an __init__.py if (dir.equals(inputPath)) { return FileVisitResult.CONTINUE; } String outFile = inputPath.relativize(dir.resolve("__init__.py")).toString(); // Version directory gets an empty __init__.py if (dir.getFileName().toString().equals(apiVersion)) { docBuilder.put(outFile, GeneratedResult.create(Doc.text("\n"), false)); // All others get become namespace packages } else { docBuilder.put( outFile, GeneratedResult.create( Doc.text("__import__('pkg_resources').declare_namespace(__name__)\n"), false)); pythonNamespacePackages.add(Joiner.on(".").join(inputPath.relativize(dir).iterator())); } return FileVisitResult.CONTINUE; }
private void createTarEntries(TarArchiveOutputStream tos, String filepath, Long filelength) throws IOException { Iterator<Path> elements = Paths.get(filepath).iterator(); StringBuilder sb = new StringBuilder(); while (elements.hasNext()) { Path path = elements.next(); String element = path.toString(); Long length = filelength; // If there are more elements to come this element is a directory // The "/" at the end tells the TarEntry it is a folder if (elements.hasNext()) { element += "/"; length = 0L; } // Each entry needs the complete path, including previous created folders. TarArchiveEntry entry = new TarArchiveEntry(sb + element); entry.setSize(length); tos.putArchiveEntry(entry); sb.append(element); } }
private static List<String> pathToStringList(final Path file) { final List<String> xs = new ArrayList<>(16); final Iterator<Path> iter = file.iterator(); while (iter.hasNext()) { xs.add(iter.next().toString()); } return xs; }
@Test public void iterator() { final Path path = fileSystem.getPath("toplevel/second/third/fourth"); final Iterator<Path> paths = path.iterator(); Assert.assertEquals("/toplevel", paths.next().toString()); Assert.assertEquals("/toplevel/second", paths.next().toString()); Assert.assertEquals("/toplevel/second/third", paths.next().toString()); Assert.assertEquals("/toplevel/second/third/fourth", paths.next().toString()); }
@Test public void iteratorRoot() { final Path path = fileSystem.getPath("/"); final Iterator<Path> paths = path.iterator(); Assert.assertFalse("Iterator should not return root element", paths.hasNext()); }