Class ByteArrayAttachment

java.lang.Object
cloud.opencode.base.email.attachment.ByteArrayAttachment
All Implemented Interfaces:
Attachment

public final class ByteArrayAttachment extends Object implements Attachment
Byte Array Email Attachment 字节数组邮件附件

Attachment implementation for in-memory byte data.

内存字节数据的附件实现。

Features | 主要功能:

  • In-memory data - 内存数据
  • No file system dependency - 无文件系统依赖
  • Defensive copy for security - 防御性拷贝确保安全

Usage Examples | 使用示例:

byte[] data = generatePdfReport();
Attachment attachment = new ByteArrayAttachment("report.pdf", data, "application/pdf");

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Immutable: Yes (defensive copy) - 不可变: 是(防御性拷贝)
Since:
JDK 25, opencode-base-email V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ByteArrayAttachment

      public ByteArrayAttachment(String fileName, byte[] data)
      Create byte array attachment 创建字节数组附件
      Parameters:
      fileName - the file name | 文件名
      data - the byte data | 字节数据
    • ByteArrayAttachment

      public ByteArrayAttachment(String fileName, byte[] data, String contentType)
      Create byte array attachment with content type 创建带内容类型的字节数组附件
      Parameters:
      fileName - the file name | 文件名
      data - the byte data | 字节数据
      contentType - the MIME type | MIME类型
  • Method Details

    • of

      public static ByteArrayAttachment of(String fileName, byte[] data, String contentType)
      Create byte array attachment 创建字节数组附件
      Parameters:
      fileName - the file name | 文件名
      data - the byte data | 字节数据
      contentType - the MIME type | MIME类型
      Returns:
      the byte array attachment | 字节数组附件
    • of

      public static ByteArrayAttachment of(String fileName, byte[] data)
      Create byte array attachment 创建字节数组附件
      Parameters:
      fileName - the file name | 文件名
      data - the byte data | 字节数据
      Returns:
      the byte array attachment | 字节数组附件
    • getFileName

      public String getFileName()
      Description copied from interface: Attachment
      Get attachment file name 获取附件文件名
      Specified by:
      getFileName in interface Attachment
      Returns:
      the file name | 文件名
    • getContentType

      public String getContentType()
      Description copied from interface: Attachment
      Get attachment MIME type 获取附件MIME类型
      Specified by:
      getContentType in interface Attachment
      Returns:
      the MIME type | MIME类型
    • getInputStream

      public InputStream getInputStream()
      Description copied from interface: Attachment
      Get attachment data as input stream 获取附件数据输入流
      Specified by:
      getInputStream in interface Attachment
      Returns:
      the input stream | 输入流
    • getSize

      public long getSize()
      Description copied from interface: Attachment
      Get attachment size in bytes 获取附件大小(字节)
      Specified by:
      getSize in interface Attachment
      Returns:
      the size in bytes | 字节大小
    • getData

      public byte[] getData()
      Get a copy of the byte data 获取字节数据的拷贝
      Returns:
      copy of the data | 数据拷贝
    • toString

      public String toString()
      Overrides:
      toString in class Object