Package: multipart_mixed
multipart_mixed
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getContent(DataSource) |
|
|
|
|
|
||||||||||||||||||||
getDataFlavors() |
|
|
|
|
|
||||||||||||||||||||
multipart_mixed() |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
writeTo(Object, String, OutputStream) |
|
|
|
|
|
Coverage
1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.handlers;
18:
19: import jakarta.activation.ActivationDataFlavor;
20: import jakarta.activation.DataSource;
21: import jakarta.mail.MessagingException;
22: import jakarta.mail.Multipart;
23: import jakarta.mail.internet.MimeMultipart;
24:
25: import java.io.IOException;
26: import java.io.OutputStream;
27:
28:
29: public class multipart_mixed extends handler_base {
30: private static ActivationDataFlavor[] myDF = {
31:         new ActivationDataFlavor(Multipart.class,
32:                                  "multipart/mixed", "Multipart")
33: };
34:
35: /**
36: * Creates a default {@code multipart_mixed}.
37: */
38: public multipart_mixed() {
39: }
40:
41: @Override
42: protected ActivationDataFlavor[] getDataFlavors() {
43:         return myDF;
44: }
45:
46: /**
47: * Return the content.
48: */
49: @Override
50: public Object getContent(DataSource ds) throws IOException {
51:         try {
52:          return new MimeMultipart(ds);
53:         } catch (MessagingException e) {
54:          IOException ioex =
55:                 new IOException("Exception while constructing MimeMultipart");
56:          ioex.initCause(e);
57:          throw ioex;
58:         }
59: }
60:
61: /**
62: * Write the object to the output stream, using the specific MIME type.
63: */
64: @Override
65: public void writeTo(Object obj, String mimeType, OutputStream os)
66:                         throws IOException {
67:•        if (!(obj instanceof Multipart))
68:          throw new IOException("\"" + getDataFlavors()[0].getMimeType() +
69:                 "\" DataContentHandler requires Multipart object, " +
70:                 "was given object of type " + obj.getClass().toString() +
71:                 "; obj.cl " + obj.getClass().getClassLoader() +
72:                 ", Multipart.cl " + Multipart.class.getClassLoader());
73:
74:         try {
75:          ((Multipart)obj).writeTo(os);
76:         } catch (MessagingException e) {
77:          IOException ioex =
78:                 new IOException("Exception writing Multipart");
79:          ioex.initCause(e);
80:          throw ioex;
81:         }
82: }
83: }