当前位置: 首页>>代码示例>>Java>>正文


Java Reflections.log方法代码示例

本文整理汇总了Java中org.reflections.Reflections.log方法的典型用法代码示例。如果您正苦于以下问题:Java Reflections.log方法的具体用法?Java Reflections.log怎么用?Java Reflections.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.reflections.Reflections的用法示例。


在下文中一共展示了Reflections.log方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forResource

import org.reflections.Reflections; //导入方法依赖的package包/类
/**
 * Gets URLs of any classpath resources with given resource pathname.
 *
 * @param  resourcePathname  resource pathname of classpath resource instances
 *           to scan for (relative to specified class loaders' classpath roots)
 * @param  returnRootPathname  whether to collect classpath root portion of
 *           URL for each resource instead of full URL of each resource
 * @param  classLoaders  not currently used (was: "set of class loaders in
 *           which to look up resource; none (empty array) to specify to use
 *           current thread's context class loader and {@link Reflections}'s
 *           class loader")
 * @returns  ...; empty set if none
 */
public static Set<URL> forResource(final String resourcePathname,
                                   final boolean returnRootPathname,
                                   final ClassLoader... classLoaders) {
  logger.debug("Scanning classpath for resources with pathname \"{}\".",
               resourcePathname);
  final Set<URL> resultUrlSet = Sets.newHashSet();

  final ClassLoader classLoader = PathScanner.class.getClassLoader();
  try {
    final Enumeration<URL> resourceUrls =
        classLoader.getResources(resourcePathname);
    while (resourceUrls.hasMoreElements()) {
      final URL resourceUrl = resourceUrls.nextElement();
      logger.trace("- found a(n) {} at {}.", resourcePathname, resourceUrl);

      int index = resourceUrl.toExternalForm().lastIndexOf(resourcePathname);
      if (index != -1 && returnRootPathname) {
        final URL classpathRootUrl =
            new URL(resourceUrl.toExternalForm().substring(0, index));
        resultUrlSet.add(classpathRootUrl);
        logger.debug("- collected resource's classpath root URL {}.",
            classpathRootUrl);
      } else {
        resultUrlSet.add(resourceUrl);
        logger.debug("- collected resource URL {}.", resourceUrl);
      }
    }
  } catch (IOException e) {
    if (Reflections.log != null) {
      Reflections.log.error(
          "Error scanning for resources named " + resourcePathname, e);
    }
  }

  return resultUrlSet;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:50,代码来源:PathScanner.java


注:本文中的org.reflections.Reflections.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。