public final P getPath(P from, String... names) throws IOException { return getPath(from, Arrays.asList(names)); }
public final P getPath(P from, Iterable<String> names) throws IOException { for (String name : names) { if (isDir(from)) { P child = getChild(from, name); if (child != null) { from = child; } else { return null; } } else { throw new UnsupportedOperationException("handle me gracefully : was expecting " + Tools.list(names) + " to resolve"); } } return from; }
public final void traverse(P path, Filter<P> filter, Visitor<P> visitor) throws IOException { String name = getName(path); if (isDir(path)) { if (filter.acceptDir(path, name)) { visitor.enterDir(path, name); for (Iterator<P> i = getChildren(path);i.hasNext();) { P child = i.next(); traverse(child, filter, visitor); } visitor.leaveDir(path, name); } } else if (filter.acceptFile(path, name)) { visitor.file(path, name); } }
public final Timestamped<Resource> getResource(Iterable<String> names) throws IOException { P path = getPath(names); if (path != null && isFile(path)) { return getResource(path); } else { return null; } }
assertEquals("", fs.getName(fs.getRoot())); assertEquals(Collections.emptyList(), fs.getNames(fs.getRoot())); P foo = fs.getPath("foo"); assertEquals("foo", fs.getName(foo)); HashSet<? extends P> fooChildren = Tools.set(fs.getChildren(foo)); assertEquals(2, fooChildren.size()); P fooBarTxt = fs.getChild(foo, "bar.txt"); assertTrue(fooChildren.contains(fooBarTxt)); assertEquals("bar.txt", fs.getName(fooBarTxt)); assertTrue(fs.isFile(fooBarTxt)); URL fooBarTxtURL = fs.getURL(fooBarTxt); String fooBarTxtContent = Tools.read(fooBarTxtURL); assertEquals("foo/bar.txt_value", fooBarTxtContent); P fooBar = fs.getChild(foo, "bar"); assertTrue(fooChildren.contains(fooBar)); assertEquals("bar", fs.getName(fooBar)); assertTrue(fs.isDir(fooBar)); P fooBarJuu = fs.getPath("foo", "bar", "juu.txt"); assertEquals("juu.txt", fs.getName(fooBarJuu)); URL fooBarJuuURL = fs.getURL(fooBarJuu); String fooBarJuuContent = Tools.read(fooBarJuuURL); assertEquals("foo/bar/juu.txt_value", fooBarJuuContent); assertEquals(Tools.list("foo", "bar", "juu.txt"), fs.getNames(fooBarJuu)); assertEquals(null, fs.getPath("juu"));
public <D> void copy(P srcPath, Filter<P> filter, ReadWriteFileSystem<D> dst, D dstPath) throws IOException { int kind = kind(srcPath, dst, dstPath); String srcName = getName(srcPath); case 0: { if (filter.acceptFile(srcPath, srcName)) { dst.updateResource(dstPath, getResource(srcPath).getObject()); D next = i.next(); String name = dst.getName(next); P a = getChild(srcPath, name); switch (kind(a, dst, next)) { default: remove = true; copy(a, filter, dst, next); for (Iterator<P> i = getChildren(srcPath);i.hasNext();) { P next = i.next(); String name = getName(next); D a = dst.getChild(dstPath, name); if (a == null) { boolean dir = isDir(next); boolean accept = dir ? filter.acceptDir(next, name) : filter.acceptFile(next, name); if (accept) { a = dst.makePath(dstPath, name); copy(next, filter, dst, a);
private <P> void doTest(ReadFileSystem<P> fs, P root) throws IOException { assertEquals(root, fs.getRoot()); assertTrue(fs.isDir(root)); assertFalse(fs.isFile(root)); assertEquals("", fs.getName(root)); Iterator<P> rootChildren = fs.getChildren(root); assertTrue(rootChildren.hasNext()); P compiler = rootChildren.next(); assertTrue(fs.isDir(compiler)); assertFalse(fs.isFile(compiler)); assertEquals("compiler", fs.getName(compiler)); Iterator<P> compilerChildren = fs.getChildren(compiler); assertTrue(compilerChildren.hasNext()); P disk = compilerChildren.next(); assertTrue(fs.isDir(disk)); assertFalse(fs.isFile(disk)); assertEquals("disk", fs.getName(disk)); Iterator<P> diskChildren = fs.getChildren(disk); assertTrue(diskChildren.hasNext()); P a = diskChildren.next(); assertFalse(fs.isDir(a)); assertTrue(fs.isFile(a)); assertEquals("A.java", fs.getName(a));
if (parent == null) { for (int i = 0;i < paths.length;i++) { paths[i] = fs.compounds[i].getRoot(); if (path != null) { ReadFileSystem compound = fs.compounds[i]; if (compound.typeOf(path) == PathType.DIR) { Iterator children = compound.getChildren(path); while (children.hasNext()) { Object child = children.next(); String name = compound.getName(child); add(name).paths[i] = child;
final ArrayList<String> beanClasses = new ArrayList<String>(); for (final ReadFileSystem fileSystem : fileSystems) { fileSystem.traverse(new Visitor.Default() { @Override public void enterDir(Object dir, String name) throws IOException { Object beansPath = fileSystem.getPath(Arrays.asList("META-INF", "beans.xml")); if (beansPath != null) { xmlURLs.add(fileSystem.getURL(beansPath));
public JavaFileObjectImpl getReadable(FileKey key) throws IOException { JavaFileObjectImpl<P> entry = entries.get(key); if (entry == null) { P file = fs.getPath(key.names); if (file != null && fs.isFile(file)) { entries.put(key, entry = new JavaFileObjectImpl<P>(location, key, fs, file)); } } return entry; }
@Override public <C extends Collection<JavaFileObject>> C list( String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse, C to) throws IOException { Iterable<String> packageNames = Spliterator.split(packageName, '.'); P dir = fs.getPath(packageNames); if (dir != null && fs.isDir(dir)) { list(packageName, dir, kinds, recurse, to); } return to; }
private void list( String packageName, P root, Set<JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> to) throws IOException { for (Iterator<P> i = fs.getChildren(root);i.hasNext();) { P child = i.next(); if (fs.isDir(child)) { if (recurse) { String name = fs.getName(child); list(packageName.isEmpty() ? name : packageName + "." + name, child, kinds, true, to); } } else { String name = fs.getName(child); FileKey key = FileKey.newName(packageName, name); if (kinds.contains(key.getKind())) { to.add(getReadable(key)); } } } } }
private <D> int kind(P srcPath, ReadWriteFileSystem<D> dst, D dstPath) throws IOException { if (isDir(srcPath)) { if (dst.isDir(dstPath)) { return 1; } else if (dst.isFile(dstPath)) { return 2; } else { return 1; } } else if (isFile(srcPath)) { if (dst.isFile(dstPath)) { return 0; } else if (dst.isDir(dstPath)) { return 3; } else { return 0; } } else { return 4; } }