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

org.elasticsearch.test.ClasspathUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.test;

import org.elasticsearch.core.PathUtils;

import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class ClasspathUtils {

    public static Path[] findFilePaths(ClassLoader classLoader, String path) throws Exception {
        Enumeration resources = classLoader.getResources(path);
        List paths = new ArrayList<>();

        while (resources.hasMoreElements()) {
            URI uri = resources.nextElement().toURI();
            if (uri.getScheme().equalsIgnoreCase("file")) {
                paths.add(PathUtils.get(uri));
            }
        }

        return paths.toArray(new Path[] {});
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy