Skip to content

Package: MultipartDataContentHandler

MultipartDataContentHandler

nameinstructionbranchcomplexitylinemethod
MultipartDataContentHandler()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getContent(DataSource)
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getTransferData(ActivationDataFlavor, DataSource)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getTransferDataFlavors()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
writeTo(Object, String, OutputStream)
M: 33 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2022 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 Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.messaging.saaj.soap;
12:
13: import java.io.*;
14: import jakarta.activation.*;
15: import com.sun.xml.messaging.saaj.packaging.mime.internet.MimeMultipart;
16: import com.sun.xml.messaging.saaj.packaging.mime.internet.ContentType;
17: import com.sun.xml.messaging.saaj.util.ByteOutputStream;
18:
19: public class MultipartDataContentHandler implements DataContentHandler {
20: private ActivationDataFlavor myDF = new ActivationDataFlavor(
21:          com.sun.xml.messaging.saaj.packaging.mime.internet.MimeMultipart.class,
22:          "multipart/mixed",
23:          "Multipart");
24:
25: public MultipartDataContentHandler() {}
26:
27: /**
28: * Return the DataFlavors for this <code>DataContentHandler</code>.
29: *
30: * @return The DataFlavors
31: */
32: @Override
33: public ActivationDataFlavor[] getTransferDataFlavors() { // throws Exception;
34:         return new ActivationDataFlavor[] { myDF };
35: }
36:
37: /**
38: * Return the Transfer Data of type DataFlavor from InputStream.
39: *
40: * @param df The DataFlavor
41: * @param ds The DataSource
42: * @return String object
43: */
44: @Override
45: public Object getTransferData(ActivationDataFlavor df, DataSource ds) {
46:         // use myDF.equals to be sure to get ActivationDataFlavor.equals,
47:         // which properly ignores Content-Type parameters in comparison
48:•        if (myDF.equals(df))
49:          return getContent(ds);
50:         else
51:          return null;
52: }
53:
54: /**
55: * Return the content.
56: *
57: * @param ds The DataSource
58: * @return content
59: */
60: @Override
61: public Object getContent(DataSource ds) {
62:         try {
63:          return new MimeMultipart(
64: ds, new ContentType(ds.getContentType()));
65:         } catch (Exception e) {
66:          return null;
67:         }
68: }
69:
70: /**
71: * Write the object to the output stream, using the specific MIME type.
72: */
73: @Override
74: public void writeTo(Object obj, String mimeType, OutputStream os)
75:                         throws IOException {
76:•        if (obj instanceof MimeMultipart) {
77:          try {
78: //TODO: temporarily allow only ByteOutputStream
79: // Need to add writeTo(OutputStream) on MimeMultipart
80: ByteOutputStream baos = null;
81:• if (os instanceof ByteOutputStream) {
82: baos = (ByteOutputStream)os;
83: } else {
84: throw new IOException("Input Stream expected to be a com.sun.xml.messaging.saaj.util.ByteOutputStream, but found " +
85: os.getClass().getName());
86: }
87:                 ((MimeMultipart)obj).writeTo(baos);
88:          } catch (Exception e) {
89:                 throw new IOException(e.toString());
90:          }
91:         }
92: }
93: }
94: