Class Attachment

java.lang.Object
com.mirth.connect.server.userutil.Attachment

public class Attachment extends Object
Used to store and retrieve details about message attachments such as the ID, MIME type, and content.
  • Constructor Details

    • Attachment

      public Attachment()
      Instantiates a new Attachment with no ID, content, or MIME type.
    • Attachment

      public Attachment(String id, byte[] content, String type)
      Instantiates a new Attachment.
      Parameters:
      id - The unique ID of the attachment.
      content - The content (byte array) to store for the attachment.
      type - The MIME type of the attachment.
    • Attachment

      public Attachment(String id, String content, String type) throws UnsupportedEncodingException
      Instantiates a new Attachment with String data using UTF-8 charset encoding.
      Parameters:
      id - The unique ID of the attachment.
      content - The string representation of the attachment content.
      type - The MIME type of the attachment.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
    • Attachment

      public Attachment(String id, String content, String charset, String type) throws UnsupportedEncodingException
      Instantiates a new Attachment with String data and a given charset encoding.
      Parameters:
      id - The unique ID of the attachment.
      content - The string representation of the attachment content.
      charset - The charset encoding to convert the string to bytes with.
      type - The MIME type of the attachment.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
  • Method Details

    • getAttachmentId

      public String getAttachmentId()
      Returns the unique replacement token for the attachment. This token should replace the attachment content in the message string, and will be used to re-attach the attachment content in the outbound message before it is sent to a downstream system.
      Returns:
      The unique replacement token for the attachment.
    • getId

      public String getId()
      Returns the unique ID for the attachment.
      Returns:
      The unique ID for the attachment.
    • setId

      public void setId(String id)
      Sets the unique ID for the attachment.
      Parameters:
      id - The unique ID to use for the attachment.
    • getContent

      public byte[] getContent()
      Returns the content of the attachment as a byte array.
      Returns:
      The content of the attachment as a byte array.
    • getContentString

      public String getContentString() throws UnsupportedEncodingException
      Returns the content of the attachment as a string, using UTF-8 encoding.
      Returns:
      The content of the attachment as a string, using UTF-8 encoding.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
    • getContentString

      public String getContentString(String charset) throws UnsupportedEncodingException
      Returns the content of the attachment as a string, using the specified charset encoding.
      Parameters:
      charset - The charset encoding to convert the content bytes to a string with.
      Returns:
      The content of the attachment as a string, using the specified charset encoding.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
    • setContent

      public void setContent(byte[] content)
      Sets the content of the attachment.
      Parameters:
      content - The content (byte array) to use for the attachment.
    • setContentString

      public void setContentString(String content) throws UnsupportedEncodingException
      Sets the content of the attachment, using UTF-8 encoding.
      Parameters:
      content - The string representation of the attachment content.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
    • setContentString

      public void setContentString(String content, String charset) throws UnsupportedEncodingException
      Sets the content of the attachment, using the specified charset encoding.
      Parameters:
      content - The string representation of the attachment content.
      charset - The charset encoding to convert the string to bytes with.
      Throws:
      UnsupportedEncodingException - If the named charset is not supported.
    • getType

      public String getType()
      Returns the MIME type of the attachment.
      Returns:
      The MIME type of the attachment.
    • setType

      public void setType(String type)
      Sets the MIME type for the attachment.
      Parameters:
      type - The MIME type to set for the attachment.