Class MultipartBodyWriter


  • public final class MultipartBodyWriter
    extends Object
    Writes a MIME multipart body as used by XOP/MTOM and SOAP with Attachments. MIME parts are written using writePart(String, String, String, List) or writePart(DataHandler, String, String, List). Calls to both methods can be mixed, i.e. it is not required to use the same method for all MIME parts. Instead, the caller should choose the most convenient method for each part (depending on the form in which the content is available). After all parts have been written, complete() must be called to write the final MIME boundary.

    The following semantics are defined for the contentTransferEncoding and contentID arguments of the two write methods:

    • The content transfer encoding specified by the contentTransferEncoding argument is applied by the write method; the caller only provides the unencoded data. At least binary and base64 are supported. If the specified encoding is not supported, the write methods may use an alternative one. In any case, the implementation ensures that the MIME part has a Content-Transfer-Encoding header appropriate for the applied encoding.
    • The content ID passed as argument is always the raw ID (without the angle brackets). The implementation translates this into a properly formatted Content-ID header.
    • Method Detail

      • writePart

        public OutputStream writePart​(String contentType,
                                      String contentTransferEncoding,
                                      String contentID,
                                      List<Header> extraHeaders)
                               throws IOException
        Start writing a MIME part. The methods returns an OutputStream that the caller can use to write the content of the MIME part. After writing the content, OutputStream.close() must be called to complete the writing of the MIME part.
        Parameters:
        contentType - the value of the Content-Type header of the MIME part; may be null
        contentTransferEncoding - the content transfer encoding to be used (see above); must not be null
        contentID - the content ID of the MIME part (see above); may be null
        extraHeaders - a list of Header objects with additional headers to write to the MIME part; may be null
        Returns:
        an output stream to write the content of the MIME part
        Throws:
        IOException - if an I/O error occurs when writing to the underlying stream
      • writePart

        public void writePart​(DataHandler dataHandler,
                              String contentTransferEncoding,
                              String contentID,
                              List<Header> extraHeaders)
                       throws IOException
        Write a MIME part. The content is provided by a DataHandler object, which also specifies the content type of the part.
        Parameters:
        dataHandler - the content of the MIME part to write
        contentTransferEncoding - the content transfer encoding to be used (see above); must not be null
        contentID - the content ID of the MIME part (see above)
        extraHeaders - a list of Header objects with additional headers to write to the MIME part
        Throws:
        IOException - if an I/O error occurs when writing the part to the underlying stream
      • complete

        public void complete()
                      throws IOException
        Complete writing of the MIME multipart package. This method does not close the underlying stream.
        Throws:
        IOException - if an I/O error occurs when writing to the underlying stream