Class BytesResource

java.lang.Object
org.miaixz.bus.core.io.resource.BytesResource
All Implemented Interfaces:
Serializable, Resource

public class BytesResource extends Object implements Resource, Serializable
基于byte[]的资源获取器 注意:此对象中getUrl方法始终返回null
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • BytesResource

      public BytesResource(byte[] bytes)
      构造
      Parameters:
      bytes - 字节数组
    • BytesResource

      public BytesResource(byte[] bytes, String name)
      构造
      Parameters:
      bytes - 字节数组
      name - 资源名称
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Resource
      获取资源名,例如文件资源的资源名为文件名
      Specified by:
      getName in interface Resource
      Returns:
      资源名
    • getUrl

      public URL getUrl()
      Description copied from interface: Resource
      获得解析后的URL,无对应URL的返回null
      Specified by:
      getUrl in interface Resource
      Returns:
      解析后的URL
    • size

      public long size()
      Description copied from interface: Resource
      获取资源大小
      Specified by:
      size in interface Resource
      Returns:
      资源大小
    • getStream

      public InputStream getStream()
      Description copied from interface: Resource
      Specified by:
      getStream in interface Resource
      Returns:
      InputStream
    • readString

      public String readString(Charset charset) throws InternalException
      Description copied from interface: Resource
      读取资源内容,读取完毕后会关闭流 关闭流并不影响下一次读取
      Specified by:
      readString in interface Resource
      Parameters:
      charset - 编码
      Returns:
      读取资源内容
      Throws:
      InternalException - 包装IOException
    • readBytes

      public byte[] readBytes() throws InternalException
      Description copied from interface: Resource
      读取资源内容,读取完毕后会关闭流 关闭流并不影响下一次读取
      Specified by:
      readBytes in interface Resource
      Returns:
      读取资源内容
      Throws:
      InternalException - 包装IOException