All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cucumber.runtime.io.ClasspathResourceIterable Maven / Gradle / Ivy

There is a newer version: 7.18.0
Show newest version
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 {
    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 iterator() {
        try {
            FlatteningIterator iterator = new FlatteningIterator();
            Enumeration resources = classLoader.getResources(path);
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                Iterator resourceIterator = resourceIteratorFactory.createIterator(url, path, suffix);
                iterator.push(resourceIterator);
            }
            return iterator;
        } catch (IOException e) {
            throw new CucumberException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy