Class ByteArrayResource

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

public class ByteArrayResource extends AbstractResource
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 Details

    • ByteArrayResource

      public ByteArrayResource(byte[] byteArray)
      Create byte array resource 创建字节数组资源
      Parameters:
      byteArray - byte array content | 字节数组内容
    • ByteArrayResource

      public ByteArrayResource(byte[] byteArray, String description)
      Create byte array resource with description 创建带描述的字节数组资源
      Parameters:
      byteArray - byte array content | 字节数组内容
      description - resource description | 资源描述
  • 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
    • isReadable

      public boolean isReadable()
      Description copied from interface: Resource
      Check if resource is readable 检查资源是否可读
      Specified by:
      isReadable in interface Resource
      Overrides:
      isReadable in class AbstractResource
      Returns:
      true if readable | 可读返回 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 | 无法确定长度时抛出
    • getBytes

      public byte[] getBytes() throws IOException
      Description copied from interface: Resource
      Read resource as byte array 读取资源为字节数组
      Returns:
      byte array | 字节数组
      Throws:
      IOException - if read fails | 读取失败时抛出
    • 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 | 无法创建相对资源时抛出
    • getByteArray

      public byte[] getByteArray()
      Get the byte array content 获取字节数组内容
      Returns:
      copy of byte array | 字节数组副本