Package org.miaixz.bus.core.io.resource
Class ResourceFinder
java.lang.Object
org.miaixz.bus.core.io.resource.ResourceFinder
资源查找器 参考Spring的PathMatchingResourcePatternResolver,实现classpath资源查找,利用
AntPathMatcher筛选资源- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringdetermineRootDir(String location) 根据给定的路径表达式,找到跟路径 根路径即不包含表达式的路径,如 "/WEB-INF/*.xml" 返回 "/WEB-INF/"查找给定表达式对应的资源protected MultiResourcefindInDir(FileResource resource, String subPattern) 遍历目录查找指定表达式匹配的文件列表protected MultiResourcefindInJar(JarResource rootResource, String subPattern) 查找jar包中的资源static ResourceFinderof()构建新的ResourceFinder,使用当前环境的类加载器static ResourceFinderof(ClassLoader classLoader) 构建新的ResourceFinder
-
Constructor Details
-
ResourceFinder
构造- Parameters:
classLoader- 类加载器,用于定义查找资源的范围
-
-
Method Details
-
of
构建新的ResourceFinder,使用当前环境的类加载器- Returns:
- ResourceFinder
-
of
构建新的ResourceFinder- Parameters:
classLoader- 类加载器,用于限定查找范围- Returns:
- ResourceFinder
-
find
查找给定表达式对应的资源- Parameters:
locationPattern- 路径表达式- Returns:
MultiResource
-
findInJar
查找jar包中的资源- Parameters:
rootResource- 根资源,为jar包文件subPattern- 子表达式,如 *.xml- Returns:
- 符合条件的资源
- Throws:
IOException- IO异常
-
findInDir
遍历目录查找指定表达式匹配的文件列表- Parameters:
resource- 文件资源subPattern- 子表达式- Returns:
- 满足条件的文件
-
determineRootDir
根据给定的路径表达式,找到跟路径 根路径即不包含表达式的路径,如 "/WEB-INF/*.xml" 返回 "/WEB-INF/"- Parameters:
location- 路径表达式- Returns:
- root dir
-