Class NestedJarResource

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

public class NestedJarResource extends AbstractResource
Nested JAR Resource - Represents a single resource entry inside a nested JAR 嵌套 JAR 资源 - 表示嵌套 JAR 中的单个资源条目

Provides access to resources that reside within a JAR that is itself embedded inside another (outer) JAR, such as those found in Spring Boot fat JARs.

提供对嵌套在外层 JAR 内部的 JAR 中资源的访问,例如 Spring Boot fat JAR 中的资源。

Features | 主要功能:

  • Access resources in nested JARs - 访问嵌套 JAR 中的资源
  • Lazy extraction via NestedJarHandler - 通过 NestedJarHandler 延迟解压
  • Standard Resource interface compliance - 符合标准 Resource 接口

Usage Examples | 使用示例:

NestedJarHandler handler = NestedJarHandler.builder().build();
NestedJarResource res = new NestedJarResource(
    handler, outerJar, "BOOT-INF/lib/inner.jar", "com/example/App.class");
if (res.exists()) {
    byte[] bytes = res.getBytes();
}

Security | 安全性:

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

    • NestedJarResource

      public NestedJarResource(NestedJarHandler handler, Path outerJarPath, String nestedJarEntry, String resourceEntry)
      Create a nested JAR resource 创建嵌套 JAR 资源
      Parameters:
      handler - the handler used to extract nested JARs | 用于解压嵌套 JAR 的处理器
      outerJarPath - path to the outer JAR file | 外层 JAR 文件路径
      nestedJarEntry - entry name of the nested JAR inside the outer JAR | 内层 JAR 在外层 JAR 中的条目名
      resourceEntry - entry name of the resource inside the nested 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 时抛出
    • 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 | 无法创建相对资源时抛出
    • getOuterJarPath

      public Path getOuterJarPath()
      Get the outer JAR path 获取外层 JAR 路径
      Returns:
      outer JAR path | 外层 JAR 路径
    • getNestedJarEntry

      public String getNestedJarEntry()
      Get the nested JAR entry name 获取嵌套 JAR 条目名
      Returns:
      nested JAR entry name | 嵌套 JAR 条目名
    • getResourceEntry

      public String getResourceEntry()
      Get the resource entry name inside the nested JAR 获取嵌套 JAR 中的资源条目名
      Returns:
      resource entry name | 资源条目名