convex.dlfs.impl.DLDirectoryStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of convex-core Show documentation
Show all versions of convex-core Show documentation
Convex core libraries and common utilities
The newest version!
package convex.dlfs.impl;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.NoSuchElementException;
import convex.core.data.ACell;
import convex.core.data.AHashMap;
import convex.core.data.AString;
import convex.core.data.AVector;
import convex.dlfs.DLFSNode;
import convex.dlfs.DLPath;
public class DLDirectoryStream implements DirectoryStream {
public class DIterator implements Iterator {
long pos=0;
@Override
public boolean hasNext() {
return pos=dirs.count()) throw new NoSuchElementException();
return base.resolve(dirs.entryAt(pos++).getKey());
}
}
private AHashMap> dirs;
private DLPath base;
public DLDirectoryStream(DLPath base, AHashMap> dirs) {
this.base=base;
this.dirs=dirs;
}
@Override
public void close() throws IOException {
// Ignore
}
@Override
public DIterator iterator() {
return new DIterator();
}
public static DLDirectoryStream create(DLPath base, AVector dirNode) {
AHashMap> dirs = DLFSNode.getDirectoryEntries(dirNode);
if (dirs==null) return null;
return new DLDirectoryStream(base,dirs);
}
}