use of org.apache.axiom.mime.Header in project webservices-axiom by apache.
the class IncomingAttachmentStreams method getNextStream.
/**
* Returns the next attachment stream in sequence.
*
* @return The next stream or null if no additional streams are left.
*/
public IncomingAttachmentInputStream getNextStream() throws OMException {
if (!readyToGetNextStream) {
throw new IllegalStateException("nextStreamNotReady");
}
Part part = null;
while (part == null && partIterator.hasNext()) {
part = partIterator.next();
// Skip the root part
if (part == rootPart) {
part = null;
}
}
if (part != null) {
IncomingAttachmentInputStream stream = new IncomingAttachmentInputStream(part.getInputStream(false), this);
for (Header header : part.getHeaders()) {
String name = header.getName();
String value = header.getValue();
if (IncomingAttachmentInputStream.HEADER_CONTENT_ID.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_TYPE.equals(name) || IncomingAttachmentInputStream.HEADER_CONTENT_LOCATION.equals(name)) {
value = value.trim();
}
stream.addHeader(name, value);
}
readyToGetNextStream = false;
return stream;
} else {
return null;
}
}
use of org.apache.axiom.mime.Header 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);
}
use of org.apache.axiom.mime.Header in project webservices-axiom by apache.
the class MultipartWriterImpl method writePart.
@Override
public void writePart(DataHandler dataHandler, String contentTransferEncoding, String contentID, List extraHeaders) throws IOException {
MimeBodyPart mimeBodyPart = new MimeBodyPart();
try {
mimeBodyPart.setDataHandler(dataHandler);
mimeBodyPart.addHeader("Content-ID", "<" + contentID + ">");
mimeBodyPart.addHeader("Content-Type", dataHandler.getContentType());
mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
mimeBodyPart.addHeader("Content-Transfer-Encoding", contentTransferEncoding);
if (extraHeaders != null) {
for (Iterator it = extraHeaders.iterator(); it.hasNext(); ) {
Header header = (Header) it.next();
mimeBodyPart.addHeader(header.getName(), header.getValue());
}
}
} catch (MessagingException ex) {
IOException ex2 = new IOException("Unable to create MimeBodyPart");
ex2.initCause(ex);
throw ex2;
}
out.write(DASH_DASH);
out.write(boundary);
out.write(CR_LF);
try {
mimeBodyPart.writeTo(out);
} catch (MessagingException ex) {
IOException ex2 = new IOException("Unable to write the MimeBodyPart object");
ex2.initCause(ex);
throw ex2;
}
out.write(CR_LF);
}
Aggregations