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

org.infinispan.commons.jdkspecific.ClasspathURLStreamHandlerProvider Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.jdkspecific;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.net.spi.URLStreamHandlerProvider;

import org.kohsuke.MetaInfServices;

/**
 * A {@link URLStreamHandlerProvider} which handles URLs with protocol "classpath".
 * It is automatically registered using the service loader pattern. It can be disabled
 * by setting the system property 
org.infinispan.urlstreamhandler.skip
* * @author Tristan Tarrant <[email protected]> * @since 12.1 **/ @MetaInfServices public class ClasspathURLStreamHandlerProvider extends URLStreamHandlerProvider { private final boolean skipProvider = Boolean.getBoolean("org.infinispan.urlstreamhandler.skip"); @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (!skipProvider && "classpath".equals(protocol)) { return new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { String path = u.getPath(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL resource = classLoader == null ? null : classLoader.getResource(path); if (resource == null) { resource = ClassLoader.getSystemClassLoader().getResource(path); } if (resource != null) { return resource.openConnection(); } else { throw new FileNotFoundException(u.toString()); } } }; } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy