Class JarResource
java.lang.Object
cloud.opencode.base.classloader.resource.AbstractResource
cloud.opencode.base.classloader.resource.JarResource
- All Implemented Interfaces:
Resource
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 Summary
ConstructorsConstructorDescriptionJarResource(URL jarUrl, String entryPath) Create JAR resource from JAR URL and entry path 从 JAR URL 和条目路径创建 JAR 资源JarResource(Path jarPath, String entryPath) Create JAR resource from JAR path and entry path 从 JAR 路径和条目路径创建 JAR 资源 -
Method Summary
Modifier and TypeMethodDescriptionlongGet content length in bytes 获取内容长度(字节)createRelative(String relativePath) Create relative resource 创建相对资源booleanexists()Check if resource exists 检查资源是否存在Get resource description 获取资源描述Get the entry path within JAR 获取 JAR 内的条目路径Get filename 获取文件名Get input stream for resource 获取资源的输入流Get the JAR file path 获取 JAR 文件路径getUrl()Get resource URL 获取资源 URLlongGet last modified timestamp 获取最后修改时间戳Methods inherited from class AbstractResource
equals, getFile, getPath, getUri, hashCode, isFile, isReadable, toString
-
Constructor Details
-
JarResource
-
JarResource
-
-
Method Details
-
exists
public boolean exists()Description copied from interface:ResourceCheck if resource exists 检查资源是否存在- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractResource- Returns:
- true if exists | 存在返回 true
-
getInputStream
Description copied from interface:ResourceGet input stream for resource 获取资源的输入流- Returns:
- input stream | 输入流
- Throws:
IOException- if cannot open stream | 无法打开流时抛出
-
getUrl
Description copied from interface:ResourceGet resource URL 获取资源 URL- Returns:
- resource URL | 资源 URL
- Throws:
IOException- if cannot get URL | 无法获取 URL 时抛出
-
contentLength
Description copied from interface:ResourceGet content length in bytes 获取内容长度(字节)- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classAbstractResource- Returns:
- content length or -1 if unknown | 内容长度,未知时返回 -1
- Throws:
IOException- if cannot determine length | 无法确定长度时抛出
-
lastModified
Description copied from interface:ResourceGet last modified timestamp 获取最后修改时间戳- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classAbstractResource- Returns:
- last modified time in milliseconds or 0 if unknown | 最后修改时间(毫秒),未知时返回 0
- Throws:
IOException- if cannot determine time | 无法确定时间时抛出
-
getFilename
Description copied from interface:ResourceGet filename 获取文件名- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource- Returns:
- filename or null | 文件名或 null
-
getDescription
-
createRelative
Description copied from interface:ResourceCreate relative resource 创建相对资源- Parameters:
relativePath- relative path | 相对路径- Returns:
- relative resource | 相对资源
- Throws:
IOException- if cannot create relative resource | 无法创建相对资源时抛出
-
getJarPath
Get the JAR file path 获取 JAR 文件路径- Returns:
- JAR file path or null | JAR 文件路径或 null
-
getEntryPath
-