Package org.apache.axiom.mime
Class MultipartBodyWriter
- java.lang.Object
-
- org.apache.axiom.mime.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 usingwritePart(String, String, String, List)
orwritePart(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
andcontentID
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 leastbinary
andbase64
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 aContent-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.
- The content transfer encoding specified by the
-
-
Constructor Summary
Constructors Constructor Description MultipartBodyWriter(OutputStream out, String boundary)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
complete()
Complete writing of the MIME multipart package.OutputStream
writePart(String contentType, String contentTransferEncoding, String contentID, List<Header> extraHeaders)
Start writing a MIME part.void
writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID, List<Header> extraHeaders)
Write a MIME part.
-
-
-
Constructor Detail
-
MultipartBodyWriter
public MultipartBodyWriter(OutputStream out, String boundary)
Constructor.- Parameters:
out
- the output stream to write the multipart body toboundary
- the MIME boundary- See Also:
UIDGenerator.generateMimeBoundary()
-
-
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 anOutputStream
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 theContent-Type
header of the MIME part; may benull
contentTransferEncoding
- the content transfer encoding to be used (see above); must not benull
contentID
- the content ID of the MIME part (see above); may benull
extraHeaders
- a list ofHeader
objects with additional headers to write to the MIME part; may benull
- 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 aDataHandler
object, which also specifies the content type of the part.- Parameters:
dataHandler
- the content of the MIME part to writecontentTransferEncoding
- the content transfer encoding to be used (see above); must not benull
contentID
- the content ID of the MIME part (see above)extraHeaders
- a list ofHeader
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
-
-