Class ResourceInfo

java.lang.Object
cloud.opencode.base.reflect.scan.ResourceInfo
Direct Known Subclasses:
ClassInfo

public class ResourceInfo extends Object
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 Details

    • ResourceInfo

      public ResourceInfo(String resourceName, ClassLoader classLoader)
      Creates a ResourceInfo 创建ResourceInfo
      Parameters:
      resourceName - the resource name | 资源名
      classLoader - the class loader | 类加载器
  • Method Details

    • getResourceName

      public String getResourceName()
      Gets the resource name 获取资源名
      Returns:
      the resource name | 资源名
    • getSimpleName

      public String getSimpleName()
      Gets the simple name (last part of path) 获取简单名称(路径最后部分)
      Returns:
      the simple name | 简单名称
    • getPackageName

      public String getPackageName()
      Gets the package name (directory path) 获取包名(目录路径)
      Returns:
      the package name | 包名
    • getClassLoader

      public ClassLoader getClassLoader()
      Gets the class loader 获取类加载器
      Returns:
      the class loader | 类加载器
    • getUrl

      public URL getUrl()
      Gets the URL for this resource 获取此资源的URL
      Returns:
      the URL or null | URL或null
    • openStream

      public InputStream openStream() throws IOException
      Opens an input stream for this resource 为此资源打开输入流
      Returns:
      the input stream | 输入流
      Throws:
      IOException - if resource cannot be opened | 如果资源无法打开
    • readBytes

      public byte[] readBytes() throws IOException
      Reads the resource as bytes 读取资源为字节数组
      Returns:
      the bytes | 字节数组
      Throws:
      IOException - if resource cannot be read | 如果资源无法读取
    • readString

      public String readString() throws IOException
      Reads the resource as string 读取资源为字符串
      Returns:
      the string | 字符串
      Throws:
      IOException - if resource cannot be read | 如果资源无法读取
    • readString

      public String readString(Charset charset) throws IOException
      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

      public String getExtension()
      Gets the file extension 获取文件扩展名
      Returns:
      the extension (without dot) or empty | 扩展名(不含点)或空
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object