use of org.apache.axiom.util.base64.Base64EncodingOutputStream in project webservices-axiom by apache.
the class MultipartBodyWriter method writePart.
/**
* Start writing a MIME part. The methods returns an {@link OutputStream} that the caller can
* use to write the content of the MIME part. After writing the content,
* {@link OutputStream#close()} must be called to complete the writing of the MIME part.
*
* @param contentType
* the value of the <tt>Content-Type</tt> header of the MIME part; may be {@code null}
* @param contentTransferEncoding
* the content transfer encoding to be used (see above); must not be
* <code>null</code>
* @param contentID
* the content ID of the MIME part (see above); may be {@code null}
* @param extraHeaders
* a list of {@link Header} objects with additional headers to write to the MIME
* part; may be {@code null}
* @return 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
*/
public OutputStream writePart(String contentType, String contentTransferEncoding, String contentID, List<Header> extraHeaders) throws IOException {
OutputStream transferEncoder;
if (contentTransferEncoding.equals("8bit") || contentTransferEncoding.equals("binary")) {
transferEncoder = out;
} else {
// We support no content transfer encodings other than 8bit, binary and base64.
transferEncoder = new Base64EncodingOutputStream(out);
contentTransferEncoding = "base64";
}
writeAscii("--");
writeAscii(boundary);
// text/plain; charset=us-ascii).
if (contentType != null) {
writeAscii("\r\nContent-Type: ");
writeAscii(contentType);
}
writeAscii("\r\nContent-Transfer-Encoding: ");
writeAscii(contentTransferEncoding);
if (contentID != null) {
writeAscii("\r\nContent-ID: <");
writeAscii(contentID);
out.write('>');
}
if (extraHeaders != null) {
for (Header header : extraHeaders) {
writeAscii("\r\n");
writeAscii(header.getName());
writeAscii(": ");
writeAscii(header.getValue());
}
}
writeAscii("\r\n\r\n");
return new PartOutputStream(transferEncoder);
}
Aggregations