jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/StringDataContentHandler.java
changeset 43852 93a527059d8a
parent 33547 e4c76ac38b12
equal deleted inserted replaced
43752:3c68ef249093 43852:93a527059d8a
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    31 import javax.activation.*;
    31 import javax.activation.*;
    32 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility;
    32 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility;
    33 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
    33 import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ContentType;
    34 
    34 
    35 /**
    35 /**
    36  * JAF data content handler for text/plain --> String
    36  * JAF data content handler for text/plain --> String
    37  *
    37  *
    38  */
    38  */
    39 public class StringDataContentHandler implements DataContentHandler {
    39 public class StringDataContentHandler implements DataContentHandler {
    40     private static ActivationDataFlavor myDF = new ActivationDataFlavor(
    40     private static ActivationDataFlavor myDF = new ActivationDataFlavor(
    41         java.lang.String.class,
    41         java.lang.String.class,
    49     /**
    49     /**
    50      * Return the DataFlavors for this <code>DataContentHandler</code>.
    50      * Return the DataFlavors for this <code>DataContentHandler</code>.
    51      *
    51      *
    52      * @return The DataFlavors
    52      * @return The DataFlavors
    53      */
    53      */
       
    54     @Override
    54     public DataFlavor[] getTransferDataFlavors() {
    55     public DataFlavor[] getTransferDataFlavors() {
    55         return new DataFlavor[] { getDF() };
    56         return new DataFlavor[] { getDF() };
    56     }
    57     }
    57 
    58 
    58     /**
    59     /**
    60      *
    61      *
    61      * @param df The DataFlavor
    62      * @param df The DataFlavor
    62      * @param ds The DataSource corresponding to the data
    63      * @param ds The DataSource corresponding to the data
    63      * @return String object
    64      * @return String object
    64      */
    65      */
       
    66     @Override
    65     public Object getTransferData(DataFlavor df, DataSource ds)
    67     public Object getTransferData(DataFlavor df, DataSource ds)
    66                         throws IOException {
    68                         throws IOException {
    67         // use myDF.equals to be sure to get ActivationDataFlavor.equals,
    69         // use myDF.equals to be sure to get ActivationDataFlavor.equals,
    68         // which properly ignores Content-Type parameters in comparison
    70         // which properly ignores Content-Type parameters in comparison
    69         if (getDF().equals(df))
    71         if (getDF().equals(df))
    70             return getContent(ds);
    72             return getContent(ds);
    71         else
    73         else
    72             return null;
    74             return null;
    73     }
    75     }
    74 
    76 
       
    77     @Override
    75     public Object getContent(DataSource ds) throws IOException {
    78     public Object getContent(DataSource ds) throws IOException {
    76         String enc = null;
    79         String enc = null;
    77         InputStreamReader is = null;
    80         InputStreamReader is = null;
    78 
    81 
    79         try {
    82         try {
   118     }
   121     }
   119 
   122 
   120     /**
   123     /**
   121      * Write the object to the output stream, using the specified MIME type.
   124      * Write the object to the output stream, using the specified MIME type.
   122      */
   125      */
       
   126     @Override
   123     public void writeTo(Object obj, String type, OutputStream os)
   127     public void writeTo(Object obj, String type, OutputStream os)
   124                         throws IOException {
   128                         throws IOException {
   125         if (!(obj instanceof String))
   129         if (!(obj instanceof String))
   126             throw new IOException("\"" + getDF().getMimeType() +
   130             throw new IOException("\"" + getDF().getMimeType() +
   127                 "\" DataContentHandler requires String object, " +
   131                 "\" DataContentHandler requires String object, " +