Class ResourceInfo
java.lang.Object
cloud.opencode.base.reflect.scan.ResourceInfo
- Direct Known Subclasses:
ClassInfo
Resource Information Holder
资源信息持有者
Holds information about a classpath resource.
持有类路径资源的信息。
Features | 主要功能:
- Resource name and URL access - 资源名和URL访问
- Resource content loading - 资源内容加载
Usage Examples | 使用示例:
ResourceInfo info = new ResourceInfo("config.properties", classLoader);
URL url = info.url();
String content = info.readAsString(StandardCharsets.UTF_8);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: No (resource name and class loader must be non-null) - 空值安全: 否(资源名和类加载器须非空)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionResourceInfo(String resourceName, ClassLoader classLoader) Creates a ResourceInfo 创建ResourceInfo -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets the class loader 获取类加载器Gets the file extension 获取文件扩展名Gets the package name (directory path) 获取包名(目录路径)Gets the resource name 获取资源名Gets the simple name (last part of path) 获取简单名称(路径最后部分)getUrl()Gets the URL for this resource 获取此资源的URLinthashCode()booleanChecks if this is a class file 检查是否为类文件booleanChecks if this is a properties file 检查是否为属性文件Opens an input stream for this resource 为此资源打开输入流byte[]Reads the resource as bytes 读取资源为字节数组Reads the resource as string 读取资源为字符串readString(Charset charset) Reads the resource as string with charset 读取资源为字符串(指定字符集)toString()
-
Constructor Details
-
ResourceInfo
Creates a ResourceInfo 创建ResourceInfo- Parameters:
resourceName- the resource name | 资源名classLoader- the class loader | 类加载器
-
-
Method Details
-
getResourceName
-
getSimpleName
Gets the simple name (last part of path) 获取简单名称(路径最后部分)- Returns:
- the simple name | 简单名称
-
getPackageName
Gets the package name (directory path) 获取包名(目录路径)- Returns:
- the package name | 包名
-
getClassLoader
-
getUrl
-
openStream
Opens an input stream for this resource 为此资源打开输入流- Returns:
- the input stream | 输入流
- Throws:
IOException- if resource cannot be opened | 如果资源无法打开
-
readBytes
Reads the resource as bytes 读取资源为字节数组- Returns:
- the bytes | 字节数组
- Throws:
IOException- if resource cannot be read | 如果资源无法读取
-
readString
Reads the resource as string 读取资源为字符串- Returns:
- the string | 字符串
- Throws:
IOException- if resource cannot be read | 如果资源无法读取
-
readString
Reads the resource as string with charset 读取资源为字符串(指定字符集)- Parameters:
charset- the charset | 字符集- Returns:
- the string | 字符串
- Throws:
IOException- if resource cannot be read | 如果资源无法读取
-
isClassFile
public boolean isClassFile()Checks if this is a class file 检查是否为类文件- Returns:
- true if class file | 如果是类文件返回true
-
isPropertiesFile
public boolean isPropertiesFile()Checks if this is a properties file 检查是否为属性文件- Returns:
- true if properties file | 如果是属性文件返回true
-
getExtension
Gets the file extension 获取文件扩展名- Returns:
- the extension (without dot) or empty | 扩展名(不含点)或空
-
equals
-
hashCode
-
toString
-