-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ClasspathResourceIterable.java
42 lines (35 loc) · 1.39 KB
/
ClasspathResourceIterable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cucumber.runtime.io;
import cucumber.runtime.CucumberException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.Iterator;
public class ClasspathResourceIterable implements Iterable<Resource> {
private final ResourceIteratorFactory resourceIteratorFactory =
new DelegatingResourceIteratorFactory(new ZipThenFileResourceIteratorFactory());
private final ClassLoader classLoader;
private final String path;
private final String suffix;
public ClasspathResourceIterable(ClassLoader classLoader, String path, String suffix) {
this.classLoader = classLoader;
this.path = path;
this.suffix = suffix;
}
@Override
public Iterator<Resource> iterator() {
try {
FlatteningIterator<Resource> iterator = new FlatteningIterator<Resource>();
Enumeration<URL> resources = classLoader.getResources(path);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
Iterator<Resource> resourceIterator = resourceIteratorFactory.createIterator(url, path, suffix);
iterator.push(resourceIterator);
}
return iterator;
} catch (IOException e) {
throw new CucumberException(e);
}
}
}