Class TypedContent

java.lang.Object
com.pnfsoftware.jeb.util.base.TypedContent

public class TypedContent extends Object
A buffer of data with a MIME type and contents properties.
  • Constructor Details

    • TypedContent

      public TypedContent(String text, String mimeType)
      Create text content.
      Parameters:
      text - text content
      mimeType - MIME type; defaults to MimeType.TEXT_PLAIN if blank
    • TypedContent

      public TypedContent(String text, String mimeType, ITypedContentProperties properties)
      Create text content.
      Parameters:
      text - text content
      mimeType - MIME type; defaults to MimeType.TEXT_PLAIN if blank
      properties - optional content properties
    • TypedContent

      public TypedContent(byte[] bytes, String mimeType)
      Create binary content.
      Parameters:
      bytes - bytes
      mimeType - MIME type; defaults to MimeType.APPLICATION_OCTETSTREAM if blank
    • TypedContent

      public TypedContent(byte[] bytes, String mimeType, String charsetName)
      Create binary content.
      Parameters:
      bytes - bytes
      mimeType - MIME type; defaults to MimeType.APPLICATION_OCTETSTREAM if blank
      charsetName - optional charset name used when converting to text
    • TypedContent

      public TypedContent(byte[] bytes, String mimeType, String charsetName, ITypedContentProperties properties)
      Create binary content.
      Parameters:
      bytes - bytes
      mimeType - MIME type; defaults to MimeType.APPLICATION_OCTETSTREAM if blank
      charsetName - optional charset name used when converting to text
      properties - optional content properties
  • Method Details

    • html

      public static TypedContent html(String text, String anchor)
      Create HTML typed content with an optional anchor.
      Parameters:
      text - HTML text
      anchor - optional anchor to associate with the content
      Returns:
      typed content
    • html

      public static TypedContent html(String text)
      Create HTML typed content.
      Parameters:
      text - HTML text
      Returns:
      typed content
    • text

      public static TypedContent text(String text)
      Create plain-text typed content.
      Parameters:
      text - text
      Returns:
      typed content
    • bytes

      public static TypedContent bytes(byte[] bytes)
      Create binary typed content.
      Parameters:
      bytes - bytes
      Returns:
      typed content
    • getText

      public String getText()
      Get this content as text.
      Returns:
      text, decoding bytes with the configured charset if needed
    • getBytes

      public byte[] getBytes()
      Get this content as bytes.
      Returns:
      bytes, encoding text with the configured charset if needed
    • getMimeType

      public String getMimeType()
      Returns:
      MIME type
    • getCharsetName

      public String getCharsetName()
      Returns:
      charset name, or null to use the default charset
    • getProperties

      public ITypedContentProperties getProperties()
      Returns:
      optional content properties
    • isText

      public boolean isText()
      Returns:
      true if this instance was created from text
    • isBinary

      public boolean isBinary()
      Returns:
      true if this instance was created from bytes