Class BasicBodyFactory

  • All Implemented Interfaces:
    BodyFactory

    public class BasicBodyFactory
    extends java.lang.Object
    implements BodyFactory
    Factory for creating message bodies.
    • Field Detail

      • defaultCharset

        private final java.nio.charset.Charset defaultCharset
    • Constructor Detail

      • BasicBodyFactory

        public BasicBodyFactory()
      • BasicBodyFactory

        public BasicBodyFactory​(java.nio.charset.Charset defaultCharset)
      • BasicBodyFactory

        public BasicBodyFactory​(boolean lenient)
    • Method Detail

      • getDefaultCharset

        public java.nio.charset.Charset getDefaultCharset()
        Returns:
        the defaultCharset
      • resolveCharset

        protected java.nio.charset.Charset resolveCharset​(java.lang.String mimeCharset)
                                                   throws java.io.UnsupportedEncodingException

        Select the Charset for the given mimeCharset string.

        If you need support for non standard or invalid mimeCharset specifications you might want to create your own derived BodyFactory extending BasicBodyFactory and overriding this method as suggested by MIME4J-218

        The default behavior is lenient, invalid mimeCharset specifications will return the defaultCharset.

        Parameters:
        mimeCharset - - the string specification for a Charset e.g. "UTF-8"
        Throws:
        java.io.UnsupportedEncodingException - if the mimeCharset is invalid
      • textBody

        public TextBody textBody​(java.lang.String text,
                                 java.lang.String mimeCharset)
                          throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • textBody

        public TextBody textBody​(byte[] content,
                                 java.nio.charset.Charset charset)
      • textBody

        public TextBody textBody​(java.io.InputStream content,
                                 java.lang.String mimeCharset)
                          throws java.io.IOException
        Description copied from interface: BodyFactory
        Creates a TextBody that holds the content of the given input stream.

        The charset corresponding to the given MIME charset name is used to decode the byte content of the input stream into a character stream when calling getReader() on the returned object. If the MIME charset has no corresponding Java charset or the Java charset cannot be used for decoding then "us-ascii" is used instead.

        Specified by:
        textBody in interface BodyFactory
        Parameters:
        content - input stream to create a message body from.
        mimeCharset - name of a MIME charset.
        Returns:
        a text body.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • textBody

        public TextBody textBody​(java.lang.String text,
                                 java.nio.charset.Charset charset)
      • textBody

        public TextBody textBody​(java.lang.String text)
      • binaryBody

        public BinaryBody binaryBody​(java.lang.String content,
                                     java.nio.charset.Charset charset)
      • binaryBody

        public BinaryBody binaryBody​(java.io.InputStream is)
                              throws java.io.IOException
        Description copied from interface: BodyFactory
        Creates a BinaryBody that holds the content of the given input stream.
        Specified by:
        binaryBody in interface BodyFactory
        Parameters:
        is - input stream to create a message body from.
        Returns:
        a binary body.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • binaryBody

        public BinaryBody binaryBody​(byte[] buf)