Package: handler_base
handler_base
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getData(ActivationDataFlavor, DataSource) |
|
|
|
|
|
||||||||||||||||||||
getTransferData(ActivationDataFlavor, DataSource) |
|
|
|
|
|
||||||||||||||||||||
getTransferDataFlavors() |
|
|
|
|
|
||||||||||||||||||||
handler_base() |
|
|
|
|
|
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.DataContentHandler;
21: import jakarta.activation.DataSource;
22:
23: import java.io.IOException;
24:
25: /**
26: * Base class for other DataContentHandlers.
27: */
28: public abstract class handler_base implements DataContentHandler {
29:
30: /**
31: * Creates a default {@code handler_base}.
32: */
33: public handler_base() {
34: }
35:
36: /**
37: * Return an array of ActivationDataFlavors that we support.
38: * Usually there will be only one.
39: *
40: * @return        array of ActivationDataFlavors that we support
41: */
42: protected abstract ActivationDataFlavor[] getDataFlavors();
43:
44: /**
45: * Given the flavor that matched, return the appropriate type of object.
46: * Usually there's only one flavor so just call getContent.
47: *
48: * @param        aFlavor        the ActivationDataFlavor
49: * @param        ds        DataSource containing the data
50: * @return        the object
51: * @exception        IOException        for errors reading the data
52: */
53: protected Object getData(ActivationDataFlavor aFlavor, DataSource ds)
54:                                 throws IOException {
55:         return getContent(ds);
56: }
57:
58: /**
59: * Return the ActivationDataFlavors for this <code>DataContentHandler</code>.
60: *
61: * @return The ActivationDataFlavors
62: */
63: @Override
64: public ActivationDataFlavor[] getTransferDataFlavors() {
65:         ActivationDataFlavor[] adf = getDataFlavors();
66:•        if (adf.length == 1)        // the common case
67:          return new ActivationDataFlavor[] { adf[0] };
68:         ActivationDataFlavor[] df = new ActivationDataFlavor[adf.length];
69:         System.arraycopy(adf, 0, df, 0, adf.length);
70:         return df;
71: }
72:
73: /**
74: * Return the Transfer Data of type ActivationDataFlavor from InputStream.
75: *
76: * @param        df        The ActivationDataFlavor
77: * @param        ds        The DataSource corresponding to the data
78: * @return        the object
79: * @exception        IOException        for errors reading the data
80: */
81: @Override
82: public Object getTransferData(ActivationDataFlavor df, DataSource ds)
83:                         throws IOException {
84:         ActivationDataFlavor[] adf = getDataFlavors();
85:•        for (int i = 0; i < adf.length; i++) {
86:          // use ActivationDataFlavor.equals, which properly
87:          // ignores Content-Type parameters in comparison
88:•         if (adf[i].equals(df))
89:                 return getData(adf[i], ds);
90:         }
91:         return null;
92: }
93: }