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

Print this page

        

*** 23,33 **** * questions. */ package java.awt.datatransfer; ! import sun.awt.datatransfer.DataTransferer; import sun.reflect.misc.ReflectUtil; import java.io.ByteArrayInputStream; import java.io.CharArrayReader; import java.io.Externalizable; --- 23,33 ---- * questions. */ package java.awt.datatransfer; ! import sun.datatransfer.DataFlavorUtil; import sun.reflect.misc.ReflectUtil; import java.io.ByteArrayInputStream; import java.io.CharArrayReader; import java.io.Externalizable;
*** 42,52 **** 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; /** --- 42,51 ----
*** 580,595 **** if (representationClass == null) { params += "null"; } else { params += representationClass.getName(); } ! if (DataTransferer.isFlavorCharsetTextType(this) && (isRepresentationClassInputStream() || isRepresentationClassByteBuffer() || byte[].class.equals(representationClass))) { ! params += ";charset=" + DataTransferer.getTextCharset(this); } return params; } /** --- 579,594 ---- if (representationClass == null) { params += "null"; } else { params += representationClass.getName(); } ! if (DataFlavorUtil.isFlavorCharsetTextType(this) && (isRepresentationClassInputStream() || isRepresentationClassByteBuffer() || byte[].class.equals(representationClass))) { ! params += ";charset=" + DataFlavorUtil.getTextCharset(this); } return params; } /**
*** 607,623 **** * @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 +";class=java.io.InputStream", "Plain Text"); } /** * Selects the best text <code>DataFlavor</code> from an array of <code> --- 606,617 ---- * @return a <code>DataFlavor</code> representing plain text * with Unicode encoding * @since 1.3 */ public static final DataFlavor getTextPlainUnicodeFlavor() { return new DataFlavor( ! "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,802 **** DataFlavor[] availableFlavors) { if (availableFlavors == null || availableFlavors.length == 0) { return null; } - if (textFlavorComparator == null) { - textFlavorComparator = new TextFlavorComparator(); - } - DataFlavor bestFlavor = Collections.max(Arrays.asList(availableFlavors), ! textFlavorComparator); 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>, --- 733,752 ---- DataFlavor[] availableFlavors) { if (availableFlavors == null || availableFlavors.length == 0) { return null; } DataFlavor bestFlavor = Collections.max(Arrays.asList(availableFlavors), ! DataFlavorUtil.getTextFlavorComparator()); if (!bestFlavor.isFlavorTextType()) { return null; } return bestFlavor; } /** * 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,1029 **** if (!mimeType.match(that.mimeType)) { return false; } if ("text".equals(getPrimaryType())) { ! if (DataTransferer.doesSubtypeSupportCharset(this) && representationClass != null && !isStandardTextRepresentationClass()) { String thisCharset = ! DataTransferer.canonicalName(this.getParameter("charset")); String thatCharset = ! DataTransferer.canonicalName(that.getParameter("charset")); if (!Objects.equals(thisCharset, thatCharset)) { return false; } } --- 963,979 ---- if (!mimeType.match(that.mimeType)) { return false; } if ("text".equals(getPrimaryType())) { ! if (DataFlavorUtil.doesSubtypeSupportCharset(this) && representationClass != null && !isStandardTextRepresentationClass()) { String thisCharset = ! DataFlavorUtil.canonicalName(this.getParameter("charset")); String thatCharset = ! DataFlavorUtil.canonicalName(that.getParameter("charset")); if (!Objects.equals(thisCharset, thatCharset)) { return false; } }
*** 1086,1099 **** // 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) && representationClass != null && !isStandardTextRepresentationClass()) { ! String charset = DataTransferer.canonicalName(getParameter("charset")); if (charset != null) { total += charset.hashCode(); } } --- 1036,1049 ---- // 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 (DataFlavorUtil.doesSubtypeSupportCharset(this) && representationClass != null && !isStandardTextRepresentationClass()) { ! String charset = DataFlavorUtil.canonicalName(getParameter("charset")); if (charset != null) { total += charset.hashCode(); } }
*** 1278,1290 **** /** * 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); } /** * Returns true if the <code>DataFlavor</code> specified represents * a serialized object. --- 1228,1239 ---- /** * Returns true if the representation class is <code>Remote</code>. * @return true if the representation class is <code>Remote</code> */ public boolean isRepresentationClassRemote() { ! return DataFlavorUtil.RMI.isRemote(representationClass); } /** * Returns true if the <code>DataFlavor</code> specified represents * a serialized object.
*** 1354,1365 **** * text flavor as described above; <code>false</code> otherwise * @see #selectBestTextFlavor * @since 1.4 */ public boolean isFlavorTextType() { ! return (DataTransferer.isFlavorCharsetTextType(this) || ! DataTransferer.isFlavorNoncharsetTextType(this)); } /** * Serializes this <code>DataFlavor</code>. */ --- 1303,1314 ---- * text flavor as described above; <code>false</code> otherwise * @see #selectBestTextFlavor * @since 1.4 */ public boolean isFlavorTextType() { ! return (DataFlavorUtil.isFlavorCharsetTextType(this) || ! DataFlavorUtil.isFlavorNoncharsetTextType(this)); } /** * Serializes this <code>DataFlavor</code>. */