Class ResourceFinder

java.lang.Object
org.miaixz.bus.core.io.resource.ResourceFinder

public class ResourceFinder extends Object
资源查找器 参考Spring的PathMatchingResourcePatternResolver,实现classpath资源查找,利用AntPathMatcher筛选资源
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ResourceFinder

      public ResourceFinder(ClassLoader classLoader)
      构造
      Parameters:
      classLoader - 类加载器,用于定义查找资源的范围
  • Method Details

    • of

      public static ResourceFinder of()
      构建新的ResourceFinder,使用当前环境的类加载器
      Returns:
      ResourceFinder
    • of

      public static ResourceFinder of(ClassLoader classLoader)
      构建新的ResourceFinder
      Parameters:
      classLoader - 类加载器,用于限定查找范围
      Returns:
      ResourceFinder
    • find

      public MultiResource find(String locationPattern)
      查找给定表达式对应的资源
      Parameters:
      locationPattern - 路径表达式
      Returns:
      MultiResource
    • findInJar

      protected MultiResource findInJar(JarResource rootResource, String subPattern) throws IOException
      查找jar包中的资源
      Parameters:
      rootResource - 根资源,为jar包文件
      subPattern - 子表达式,如 *.xml
      Returns:
      符合条件的资源
      Throws:
      IOException - IO异常
    • findInDir

      protected MultiResource findInDir(FileResource resource, String subPattern)
      遍历目录查找指定表达式匹配的文件列表
      Parameters:
      resource - 文件资源
      subPattern - 子表达式
      Returns:
      满足条件的文件
    • determineRootDir

      protected String determineRootDir(String location)
      根据给定的路径表达式,找到跟路径 根路径即不包含表达式的路径,如 "/WEB-INF/*.xml" 返回 "/WEB-INF/"
      Parameters:
      location - 路径表达式
      Returns:
      root dir