Class ByteArrayResource
java.lang.Object
cloud.opencode.base.classloader.resource.AbstractResource
cloud.opencode.base.classloader.resource.ByteArrayResource
- All Implemented Interfaces:
Resource
ByteArray Resource - Resource from byte array
字节数组资源 - 从字节数组加载的资源
Represents a resource backed by a byte array in memory.
表示由内存中字节数组支持的资源。
Features | 主要功能:
- In-memory resource - 内存资源
- No I/O operations - 无 I/O 操作
- Reusable content - 可重复使用的内容
Usage Examples | 使用示例:
byte[] data = "config content".getBytes();
Resource resource = new ByteArrayResource(data);
Resource resource = new ByteArrayResource(data, "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 Summary
ConstructorsConstructorDescriptionByteArrayResource(byte[] byteArray) Create byte array resource 创建字节数组资源ByteArrayResource(byte[] byteArray, String description) Create byte array resource with description 创建带描述的字节数组资源 -
Method Summary
Modifier and TypeMethodDescriptionlongGet content length in bytes 获取内容长度(字节)createRelative(String relativePath) Create relative resource 创建相对资源booleanexists()Check if resource exists 检查资源是否存在byte[]Get the byte array content 获取字节数组内容byte[]getBytes()Read resource as byte array 读取资源为字节数组Get resource description 获取资源描述Get input stream for resource 获取资源的输入流getUrl()Get resource URL 获取资源 URLbooleanCheck if resource is readable 检查资源是否可读Methods inherited from class AbstractResource
equals, getFile, getFilename, getPath, getUri, hashCode, isFile, lastModified, toString
-
Constructor Details
-
ByteArrayResource
public ByteArrayResource(byte[] byteArray) Create byte array resource 创建字节数组资源- Parameters:
byteArray- byte array content | 字节数组内容
-
ByteArrayResource
Create byte array resource with description 创建带描述的字节数组资源- Parameters:
byteArray- byte array content | 字节数组内容description- resource description | 资源描述
-
-
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
-
isReadable
public boolean isReadable()Description copied from interface:ResourceCheck if resource is readable 检查资源是否可读- Specified by:
isReadablein interfaceResource- Overrides:
isReadablein classAbstractResource- Returns:
- true if readable | 可读返回 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 | 无法确定长度时抛出
-
getBytes
Description copied from interface:ResourceRead resource as byte array 读取资源为字节数组- Returns:
- byte array | 字节数组
- Throws:
IOException- if read fails | 读取失败时抛出
-
getDescription
-
createRelative
Description copied from interface:ResourceCreate relative resource 创建相对资源- Parameters:
relativePath- relative path | 相对路径- Returns:
- relative resource | 相对资源
- Throws:
IOException- if cannot create relative resource | 无法创建相对资源时抛出
-
getByteArray
public byte[] getByteArray()Get the byte array content 获取字节数组内容- Returns:
- copy of byte array | 字节数组副本
-