Class StorageBodyFactory

  • All Implemented Interfaces:
    BodyFactory

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

      • FALLBACK_CHARSET

        private static final java.nio.charset.Charset FALLBACK_CHARSET
    • Constructor Detail

      • StorageBodyFactory

        public StorageBodyFactory()
        Creates a new BodyFactory instance that uses the default storage provider for creating message bodies from input streams.
      • StorageBodyFactory

        public StorageBodyFactory​(StorageProvider storageProvider,
                                  DecodeMonitor monitor)
        Creates a new BodyFactory instance that uses the given storage provider for creating message bodies from input streams.
        Parameters:
        storageProvider - a storage provider or null to use the default one.
    • Method Detail

      • getStorageProvider

        public StorageProvider getStorageProvider()
        Returns the StorageProvider this BodyFactory uses to create message bodies from input streams.
        Returns:
        a StorageProvider.
      • binaryBody

        public BinaryBody binaryBody​(java.io.InputStream is)
                              throws java.io.IOException
        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​(Storage storage)
                              throws java.io.IOException
        Creates a BinaryBody that holds the content of the given Storage.

        Note that the caller must not invoke delete() on the given Storage object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (see Disposable.dispose()).

        Parameters:
        storage - storage to create a message body from.
        Returns:
        a binary body.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • textBody

        public TextBody textBody​(java.io.InputStream is)
                          throws java.io.IOException
        Creates a TextBody that holds the content of the given input stream.

        "us-ascii" is used to decode the byte content of the Storage into a character stream when calling getReader() on the returned object.

        Parameters:
        is - input stream to create a message body from.
        Returns:
        a text body.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • textBody

        public TextBody textBody​(java.io.InputStream is,
                                 java.lang.String mimeCharset)
                          throws java.io.IOException
        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:
        is - 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​(Storage storage)
                          throws java.io.IOException
        Creates a TextBody that holds the content of the given Storage.

        "us-ascii" is used to decode the byte content of the Storage into a character stream when calling getReader() on the returned object.

        Note that the caller must not invoke delete() on the given Storage object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (see Disposable.dispose()).

        Parameters:
        storage - storage to create a message body from.
        Returns:
        a text body.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • textBody

        public TextBody textBody​(Storage storage,
                                 java.lang.String mimeCharset)
                          throws java.io.IOException
        Creates a TextBody that holds the content of the given Storage.

        The charset corresponding to the given MIME charset name is used to decode the byte content of the Storage 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.

        Note that the caller must not invoke delete() on the given Storage object after it has been passed to this method. Instead the message body created by this method takes care of deleting the storage when it gets disposed of (see Disposable.dispose()).

        Parameters:
        storage - storage 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)
        Creates a TextBody that holds the content of the given string.

        "us-ascii" is used to encode the characters of the string into a byte stream when calling writeTo(OutputStream) on the returned object.

        Parameters:
        text - text to create a message body from.
        Returns:
        a text body.
      • textBody

        public TextBody textBody​(java.lang.String text,
                                 java.lang.String mimeCharset)
        Creates a TextBody that holds the content of the given string.

        The charset corresponding to the given MIME charset name is used to encode the characters of the string into a byte stream when calling writeTo(OutputStream) on the returned object. If the MIME charset has no corresponding Java charset or the Java charset cannot be used for encoding then "us-ascii" is used instead.

        Parameters:
        text - text to create a message body from.
        mimeCharset - name of a MIME charset.
        Returns:
        a text body.
      • toJavaCharset

        private static java.nio.charset.Charset toJavaCharset​(java.lang.String mimeCharset,
                                                              boolean forEncoding,
                                                              DecodeMonitor monitor)