Java 类org.apache.logging.log4j.core.helpers.Loader 实例源码

项目:log4j2    文件:ConfigurationFactory.java   
/**
 * Retrieve the configuration via the ClassLoader.
 * @param resource The resource to load.
 * @param loader The default ClassLoader to use.
 * @return The ConfigurationSource for the configuration.
 */
protected ConfigurationSource getInputFromResource(final String resource, final ClassLoader loader) {
    final URL url = Loader.getResource(resource, loader);
    if (url == null) {
        return null;
    }
    InputStream is = null;
    try {
        is = url.openStream();
    } catch (final IOException ioe) {
        return null;
    }
    if (is == null) {
        return null;
    }

    if (FileUtils.isFile(url)) {
        try {
            return new ConfigurationSource(is, FileUtils.fileFromURI((url.toURI())));
        } catch (final URISyntaxException ex) {
            // Just ignore the exception.
        }
    }
    return new ConfigurationSource(is, resource);
}
项目:log4j2    文件:ResolverUtil.java   
/**
 * Returns the classloader that will be used for scanning for classes. If no explicit
 * ClassLoader has been set by the calling, the context class loader will be used.
 *
 * @return the ClassLoader that will be used to scan for classes
 */
public ClassLoader getClassLoader() {
    return classloader != null ? classloader : (classloader = Loader.getClassLoader(ResolverUtil.class, null));
}