Class ResourceClassLoader

java.lang.Object
java.lang.ClassLoader
cloud.opencode.base.classloader.loader.ResourceClassLoader

public class ResourceClassLoader extends ClassLoader
Resource ClassLoader - Focused on resource loading 资源类加载器 - 专注于资源加载

ClassLoader that focuses on resource loading from multiple paths.

专注于从多个路径加载资源的类加载器。

Features | 主要功能:

  • Multiple resource paths - 多资源路径
  • Dynamic path management - 动态路径管理
  • Resource refresh - 资源刷新

Usage Examples | 使用示例:

ResourceClassLoader loader = ResourceClassLoader.create(Path.of("/resources"));
loader.addResourcePath(Path.of("/extra-resources"));
URL resource = loader.getResource("config.yml");

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-classloader V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ResourceClassLoader

      public ResourceClassLoader()
      Create resource classloader with default parent 使用默认父加载器创建资源类加载器
    • ResourceClassLoader

      public ResourceClassLoader(ClassLoader parent)
      Create resource classloader with specified parent 使用指定父加载器创建资源类加载器
      Parameters:
      parent - parent classloader | 父类加载器
  • Method Details

    • create

      public static ResourceClassLoader create(Path... resourcePaths)
      Create resource classloader with resource paths 使用资源路径创建资源类加载器
      Parameters:
      resourcePaths - resource paths | 资源路径
      Returns:
      new ResourceClassLoader | 新的资源类加载器
    • create

      public static ResourceClassLoader create(ClassLoader parent, Path... resourcePaths)
      Create resource classloader with parent and resource paths 使用父加载器和资源路径创建资源类加载器
      Parameters:
      parent - parent classloader | 父类加载器
      resourcePaths - resource paths | 资源路径
      Returns:
      new ResourceClassLoader | 新的资源类加载器
    • addResourcePath

      public void addResourcePath(Path path)
      Add resource path 添加资源路径
      Parameters:
      path - resource path | 资源路径
    • removeResourcePath

      public void removeResourcePath(Path path)
      Remove resource path 移除资源路径
      Parameters:
      path - resource path | 资源路径
    • getResourcePaths

      public List<Path> getResourcePaths()
      Get all resource paths 获取所有资源路径
      Returns:
      list of resource paths | 资源路径列表
    • clearResourcePaths

      public void clearResourcePaths()
      Clear all resource paths 清除所有资源路径
    • getResource

      public URL getResource(String name)
      Overrides:
      getResource in class ClassLoader
    • getResourceAsStream

      public InputStream getResourceAsStream(String name)
      Overrides:
      getResourceAsStream in class ClassLoader
    • getResources

      public Enumeration<URL> getResources(String name) throws IOException
      Overrides:
      getResources in class ClassLoader
      Throws:
      IOException
    • refresh

      public void refresh()
      Refresh resources (re-scan paths) 刷新资源(重新扫描路径)
    • resourceExists

      public boolean resourceExists(String name)
      Check if resource exists 检查资源是否存在
      Parameters:
      name - resource name | 资源名
      Returns:
      true if exists | 存在返回 true
    • listResources

      public List<String> listResources(String path)
      List resources in a path 列出路径中的资源
      Parameters:
      path - path relative to resource roots | 相对于资源根的路径
      Returns:
      list of resource names | 资源名列表