Search in sources :

Example 1 with Base64EncodingOutputStream

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);
}
Also used : Header(org.apache.axiom.mime.Header) OutputStream(java.io.OutputStream) Base64EncodingOutputStream(org.apache.axiom.util.base64.Base64EncodingOutputStream) Base64EncodingOutputStream(org.apache.axiom.util.base64.Base64EncodingOutputStream)

Aggregations

OutputStream (java.io.OutputStream)1 Header (org.apache.axiom.mime.Header)1 Base64EncodingOutputStream (org.apache.axiom.util.base64.Base64EncodingOutputStream)1