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

fr.univnantes.termsuite.utils.ClasspathURLHandler Maven / Gradle / Ivy

package fr.univnantes.termsuite.utils;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

public class ClasspathURLHandler extends URLStreamHandler {
    /** The classloader to find resources from. */
    private final ClassLoader classLoader;

    public ClasspathURLHandler() {
        this.classLoader = getClass().getClassLoader();
    }

    public ClasspathURLHandler(ClassLoader classLoader) {
        this.classLoader = classLoader;
    }

    @Override
    protected URLConnection openConnection(URL u) throws IOException {
        final URL resourceUrl = classLoader.getResource(u.getPath());
        if(resourceUrl == null)
        	throw new IOException("Could not get resource path " + u.getPath() + " from classpath");
        return resourceUrl.openConnection();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy