Class JarResource

java.lang.Object
cloud.opencode.base.classloader.resource.AbstractResource
cloud.opencode.base.classloader.resource.JarResource
All Implemented Interfaces:
Resource

public class JarResource extends AbstractResource
JAR Resource - Resource from JAR file JAR 资源 - 从 JAR 文件加载的资源

Represents a resource that exists inside a JAR file.

表示存在于 JAR 文件内部的资源。

Features | 主要功能:

  • Load resources from JAR files - 从 JAR 文件加载资源
  • Access JAR entry metadata - 访问 JAR 条目元数据
  • Support nested JAR paths - 支持嵌套 JAR 路径

Usage Examples | 使用示例:

Resource resource = new JarResource(Path.of("lib/app.jar"), "config/app.yml");
String content = resource.getString();

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

    • JarResource

      public JarResource(Path jarPath, String entryPath)
      Create JAR resource from JAR path and entry path 从 JAR 路径和条目路径创建 JAR 资源
      Parameters:
      jarPath - path to JAR file | JAR 文件路径
      entryPath - path within JAR | JAR 内路径
    • JarResource

      public JarResource(URL jarUrl, String entryPath)
      Create JAR resource from JAR URL and entry path 从 JAR URL 和条目路径创建 JAR 资源
      Parameters:
      jarUrl - URL to JAR file | JAR 文件 URL
      entryPath - path within JAR | JAR 内路径
  • Method Details

    • exists

      public boolean exists()
      Description copied from interface: Resource
      Check if resource exists 检查资源是否存在
      Specified by:
      exists in interface Resource
      Overrides:
      exists in class AbstractResource
      Returns:
      true if exists | 存在返回 true
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: Resource
      Get input stream for resource 获取资源的输入流
      Returns:
      input stream | 输入流
      Throws:
      IOException - if cannot open stream | 无法打开流时抛出
    • getUrl

      public URL getUrl() throws IOException
      Description copied from interface: Resource
      Get resource URL 获取资源 URL
      Returns:
      resource URL | 资源 URL
      Throws:
      IOException - if cannot get URL | 无法获取 URL 时抛出
    • contentLength

      public long contentLength() throws IOException
      Description copied from interface: Resource
      Get content length in bytes 获取内容长度(字节)
      Specified by:
      contentLength in interface Resource
      Overrides:
      contentLength in class AbstractResource
      Returns:
      content length or -1 if unknown | 内容长度,未知时返回 -1
      Throws:
      IOException - if cannot determine length | 无法确定长度时抛出
    • lastModified

      public long lastModified() throws IOException
      Description copied from interface: Resource
      Get last modified timestamp 获取最后修改时间戳
      Specified by:
      lastModified in interface Resource
      Overrides:
      lastModified in class AbstractResource
      Returns:
      last modified time in milliseconds or 0 if unknown | 最后修改时间(毫秒),未知时返回 0
      Throws:
      IOException - if cannot determine time | 无法确定时间时抛出
    • getFilename

      public String getFilename()
      Description copied from interface: Resource
      Get filename 获取文件名
      Specified by:
      getFilename in interface Resource
      Overrides:
      getFilename in class AbstractResource
      Returns:
      filename or null | 文件名或 null
    • getDescription

      public String getDescription()
      Description copied from interface: Resource
      Get resource description 获取资源描述
      Returns:
      description | 描述
    • createRelative

      public Resource createRelative(String relativePath) throws IOException
      Description copied from interface: Resource
      Create relative resource 创建相对资源
      Parameters:
      relativePath - relative path | 相对路径
      Returns:
      relative resource | 相对资源
      Throws:
      IOException - if cannot create relative resource | 无法创建相对资源时抛出
    • getJarPath

      public Path getJarPath()
      Get the JAR file path 获取 JAR 文件路径
      Returns:
      JAR file path or null | JAR 文件路径或 null
    • getEntryPath

      public String getEntryPath()
      Get the entry path within JAR 获取 JAR 内的条目路径
      Returns:
      entry path | 条目路径