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, 2021 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: /**
26: * Return the DataFlavors for this <code>DataContentHandler</code>.
27: *
28: * @return The DataFlavors
29: */
30: @Override
31: public ActivationDataFlavor[] getTransferDataFlavors() { // throws Exception;
32:         return new ActivationDataFlavor[] { myDF };
33: }
34:
35: /**
36: * Return the Transfer Data of type DataFlavor from InputStream.
37: *
38: * @param df The DataFlavor
39: * @param ds The DataSource
40: * @return String object
41: */
42: @Override
43: public Object getTransferData(ActivationDataFlavor df, DataSource ds) {
44:         // use myDF.equals to be sure to get ActivationDataFlavor.equals,
45:         // which properly ignores Content-Type parameters in comparison
46:•        if (myDF.equals(df))
47:          return getContent(ds);
48:         else
49:          return null;
50: }
51:
52: /**
53: * Return the content.
54: *
55: * @param ds The DataSource
56: * @return content
57: */
58: @Override
59: public Object getContent(DataSource ds) {
60:         try {
61:          return new MimeMultipart(
62: ds, new ContentType(ds.getContentType()));
63:         } catch (Exception e) {
64:          return null;
65:         }
66: }
67:
68: /**
69: * Write the object to the output stream, using the specific MIME type.
70: */
71: @Override
72: public void writeTo(Object obj, String mimeType, OutputStream os)
73:                         throws IOException {
74:•        if (obj instanceof MimeMultipart) {
75:          try {
76: //TODO: temporarily allow only ByteOutputStream
77: // Need to add writeTo(OutputStream) on MimeMultipart
78: ByteOutputStream baos = null;
79:• if (os instanceof ByteOutputStream) {
80: baos = (ByteOutputStream)os;
81: } else {
82: throw new IOException("Input Stream expected to be a com.sun.xml.messaging.saaj.util.ByteOutputStream, but found " +
83: os.getClass().getName());
84: }
85:                 ((MimeMultipart)obj).writeTo(baos);
86:          } catch (Exception e) {
87:                 throw new IOException(e.toString());
88:          }
89:         }
90: }
91: }
92: