Record Class PdfAttachment

java.lang.Object
java.lang.Record
com.nsdev.lettergenerator.document.PdfAttachment
Record Components:
data - complete unencrypted PDF bytes, copied on construction and access

public record PdfAttachment(byte[] data) extends Record
Owned, validated PDF pages to append after a generated letter. Encrypted and empty PDFs are rejected; equality and hashing compare encoded contents. Attachments are accepted only by the standard output profile because merging arbitrary PDFs cannot preserve profile guarantees.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PdfAttachment(byte[] data)
    Takes a defensive snapshot and checks PDF readability without retaining parser state.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the value of the data record component.
    boolean
    equals(Object other)
    Compares exact encoded PDF contents.
    int
    Returns a hash code value for this object.
    of(byte[] bytes)
    Snapshots an already encoded PDF.
    of(Path path)
    Reads an explicitly trusted local PDF path once.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PdfAttachment

      public PdfAttachment(byte[] data)
      Takes a defensive snapshot and checks PDF readability without retaining parser state.
      Parameters:
      data - complete nonempty PDF bytes
      Throws:
      InvalidLetterException - if the bytes are absent, invalid, encrypted or have no pages
  • Method Details

    • of

      public static PdfAttachment of(byte[] bytes)
      Snapshots an already encoded PDF.
      Parameters:
      bytes - PDF contents
      Returns:
      independent immutable attachment
    • of

      public static PdfAttachment of(Path path)
      Reads an explicitly trusted local PDF path once.
      Parameters:
      path - non-null PDF source
      Returns:
      immutable attachment independent of later file changes
      Throws:
      InvalidLetterException - if the path cannot be read or is not an accepted PDF
    • data

      public byte[] data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • equals

      public boolean equals(Object other)
      Compares exact encoded PDF contents.
      Specified by:
      equals in class Record
      Parameters:
      other - nullable candidate
      Returns:
      whether the encoded PDFs match
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object