aQute.libg.fileiterator.FileIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bndlib Show documentation
Show all versions of bndlib Show documentation
A Swiss Army Knife for OSGi
package aQute.libg.fileiterator;
import java.io.*;
import java.util.*;
public class FileIterator implements Iterator {
File dir;
int n = 0;
FileIterator next;
public FileIterator(File nxt) {
assert nxt.isDirectory();
this.dir = nxt;
}
public boolean hasNext() {
if (next != null)
return next.hasNext();
else
return n < dir.list().length;
}
public File next() {
if (next != null) {
File answer = next.next();
if (!next.hasNext())
next = null;
return answer;
} else {
File nxt = dir.listFiles()[n++];
if (nxt.isDirectory()) {
next = new FileIterator(nxt);
return nxt;
} else if (nxt.isFile()) {
return nxt;
} else
throw new IllegalStateException("File disappeared");
}
}
public void remove() {
throw new UnsupportedOperationException(
"Cannot remove from a file iterator");
}
}