cucumber.runtime.io.FileResourceIterator Maven / Gradle / Ivy
package cucumber.runtime.io;
import java.io.File;
import java.io.FileFilter;
import java.util.Iterator;
import static cucumber.runtime.io.Helpers.hasSuffix;
import static java.util.Arrays.asList;
public class FileResourceIterator implements Iterator {
private final FlatteningIterator flatteningIterator = new FlatteningIterator();
public static FileResourceIterator createFileResourceIterator(File root, File file, final String suffix) {
return new FileResourceIterator(root, file, suffix, false);
}
public static FileResourceIterator createClasspathFileResourceIterator(File root, File file, final String suffix) {
return new FileResourceIterator(root, file, suffix, true);
}
private FileResourceIterator(File root, File file, final String suffix, boolean classpathFileResourceIterator) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory() || hasSuffix(suffix, file.getPath());
}
};
flatteningIterator.push(new FileIterator(root, file, filter, classpathFileResourceIterator));
}
@Override
public boolean hasNext() {
return flatteningIterator.hasNext();
}
@Override
public Resource next() {
return flatteningIterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
/**
* Iterator to iterate over all the files contained in a directory. It returns
* a File object for non directories or a new FileIterator object for directories.
*/
private static class FileIterator implements Iterator