src/share/classes/java/awt/datatransfer/DataFlavor.java

Print this page

        

@@ -23,11 +23,11 @@
  * questions.
  */
 
 package java.awt.datatransfer;
 
-import sun.awt.datatransfer.DataTransferer;
+import sun.datatransfer.DataFlavorUtil;
 import sun.reflect.misc.ReflectUtil;
 
 import java.io.ByteArrayInputStream;
 import java.io.CharArrayReader;
 import java.io.Externalizable;

@@ -42,11 +42,10 @@
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.Objects;
 
 import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
 
 /**

@@ -580,16 +579,16 @@
         if (representationClass == null) {
            params += "null";
         } else {
            params += representationClass.getName();
         }
-        if (DataTransferer.isFlavorCharsetTextType(this) &&
+        if (DataFlavorUtil.isFlavorCharsetTextType(this) &&
             (isRepresentationClassInputStream() ||
              isRepresentationClassByteBuffer() ||
              byte[].class.equals(representationClass)))
         {
-            params += ";charset=" + DataTransferer.getTextCharset(this);
+            params += ";charset=" + DataFlavorUtil.getTextCharset(this);
         }
         return params;
     }
 
     /**

@@ -607,17 +606,12 @@
      * @return a <code>DataFlavor</code> representing plain text
      *    with Unicode encoding
      * @since 1.3
      */
     public static final DataFlavor getTextPlainUnicodeFlavor() {
-        String encoding = null;
-        DataTransferer transferer = DataTransferer.getInstance();
-        if (transferer != null) {
-            encoding = transferer.getDefaultUnicodeEncoding();
-        }
         return new DataFlavor(
-            "text/plain;charset="+encoding
+            "text/plain;charset=" + DataFlavorUtil.getDesktopService().getDefaultUnicodeEncoding()
             +";class=java.io.InputStream", "Plain Text");
     }
 
     /**
      * Selects the best text <code>DataFlavor</code> from an array of <code>

@@ -739,64 +733,20 @@
                                        DataFlavor[] availableFlavors) {
         if (availableFlavors == null || availableFlavors.length == 0) {
             return null;
         }
 
-        if (textFlavorComparator == null) {
-            textFlavorComparator = new TextFlavorComparator();
-        }
-
         DataFlavor bestFlavor = Collections.max(Arrays.asList(availableFlavors),
-                                                textFlavorComparator);
+                                                DataFlavorUtil.getTextFlavorComparator());
 
         if (!bestFlavor.isFlavorTextType()) {
             return null;
         }
 
         return bestFlavor;
     }
 
-    private static Comparator<DataFlavor> textFlavorComparator;
-
-    static class TextFlavorComparator
-            extends DataTransferer.DataFlavorComparator {
-
-        /**
-         * Compares two <code>DataFlavor</code> objects. Returns a negative
-         * integer, zero, or a positive integer as the first
-         * <code>DataFlavor</code> is worse than, equal to, or better than the
-         * second.
-         * <p>
-         * <code>DataFlavor</code>s are ordered according to the rules outlined
-         * for <code>selectBestTextFlavor</code>.
-         *
-         * @param flavor1 the first <code>DataFlavor</code> to be compared
-         * @param flavor2 the second <code>DataFlavor</code> to be compared
-         * @return a negative integer, zero, or a positive integer as the first
-         *         argument is worse, equal to, or better than the second
-         * @throws ClassCastException if either of the arguments is not an
-         *         instance of <code>DataFlavor</code>
-         * @throws NullPointerException if either of the arguments is
-         *         <code>null</code>
-         *
-         * @see #selectBestTextFlavor
-         */
-        public int compare(DataFlavor flavor1, DataFlavor flavor2) {
-            if (flavor1.isFlavorTextType()) {
-                if (flavor2.isFlavorTextType()) {
-                    return super.compare(flavor1, flavor2);
-                } else {
-                    return 1;
-                }
-            } else if (flavor2.isFlavorTextType()) {
-                return -1;
-            } else {
-                return 0;
-            }
-        }
-    }
-
     /**
      * Gets a Reader for a text flavor, decoded, if necessary, for the expected
      * charset (encoding). The supported representation classes are
      * <code>java.io.Reader</code>, <code>java.lang.String</code>,
      * <code>java.nio.CharBuffer</code>, <code>[C</code>,

@@ -1013,17 +963,17 @@
             if (!mimeType.match(that.mimeType)) {
                 return false;
             }
 
             if ("text".equals(getPrimaryType())) {
-                if (DataTransferer.doesSubtypeSupportCharset(this)
+                if (DataFlavorUtil.doesSubtypeSupportCharset(this)
                         && representationClass != null
                         && !isStandardTextRepresentationClass()) {
                     String thisCharset =
-                            DataTransferer.canonicalName(this.getParameter("charset"));
+                            DataFlavorUtil.canonicalName(this.getParameter("charset"));
                     String thatCharset =
-                            DataTransferer.canonicalName(that.getParameter("charset"));
+                            DataFlavorUtil.canonicalName(that.getParameter("charset"));
                     if (!Objects.equals(thisCharset, thatCharset)) {
                         return false;
                     }
                 }
 

@@ -1086,14 +1036,14 @@
             // Do not add subType.hashCode() to the total. equals uses
             // MimeType.match which reports a match if one or both of the
             // subTypes is '*', regardless of the other subType.
 
             if ("text".equals(primaryType)) {
-                if (DataTransferer.doesSubtypeSupportCharset(this)
+                if (DataFlavorUtil.doesSubtypeSupportCharset(this)
                         && representationClass != null
                         && !isStandardTextRepresentationClass()) {
-                    String charset = DataTransferer.canonicalName(getParameter("charset"));
+                    String charset = DataFlavorUtil.canonicalName(getParameter("charset"));
                     if (charset != null) {
                         total += charset.hashCode();
                     }
                 }
 

@@ -1278,13 +1228,12 @@
 
    /**
     * Returns true if the representation class is <code>Remote</code>.
     * @return true if the representation class is <code>Remote</code>
     */
-
     public boolean isRepresentationClassRemote() {
-        return DataTransferer.isRemote(representationClass);
+        return DataFlavorUtil.RMI.isRemote(representationClass);
     }
 
    /**
     * Returns true if the <code>DataFlavor</code> specified represents
     * a serialized object.

@@ -1354,12 +1303,12 @@
      *         text flavor as described above; <code>false</code> otherwise
      * @see #selectBestTextFlavor
      * @since 1.4
      */
     public boolean isFlavorTextType() {
-        return (DataTransferer.isFlavorCharsetTextType(this) ||
-                DataTransferer.isFlavorNoncharsetTextType(this));
+        return (DataFlavorUtil.isFlavorCharsetTextType(this) ||
+                DataFlavorUtil.isFlavorNoncharsetTextType(this));
     }
 
    /**
     * Serializes this <code>DataFlavor</code>.
     */