23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package java.awt.datatransfer; |
26 package java.awt.datatransfer; |
27 |
27 |
28 import java.io.*; |
|
29 import java.nio.*; |
|
30 import java.util.*; |
|
31 |
|
32 import sun.awt.datatransfer.DataTransferer; |
28 import sun.awt.datatransfer.DataTransferer; |
33 import sun.reflect.misc.ReflectUtil; |
29 import sun.reflect.misc.ReflectUtil; |
|
30 |
|
31 import java.io.ByteArrayInputStream; |
|
32 import java.io.CharArrayReader; |
|
33 import java.io.Externalizable; |
|
34 import java.io.IOException; |
|
35 import java.io.InputStream; |
|
36 import java.io.InputStreamReader; |
|
37 import java.io.ObjectInput; |
|
38 import java.io.ObjectOutput; |
|
39 import java.io.OptionalDataException; |
|
40 import java.io.Reader; |
|
41 import java.io.StringReader; |
|
42 import java.io.UnsupportedEncodingException; |
|
43 import java.nio.ByteBuffer; |
|
44 import java.nio.CharBuffer; |
|
45 import java.util.Arrays; |
|
46 import java.util.Collections; |
|
47 import java.util.Comparator; |
|
48 import java.util.Objects; |
34 |
49 |
35 import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; |
50 import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION; |
36 |
51 |
37 /** |
52 /** |
38 * A {@code DataFlavor} provides meta information about data. {@code DataFlavor} |
53 * A {@code DataFlavor} provides meta information about data. {@code DataFlavor} |
499 * |
514 * |
500 * @throws MimeTypeParseException |
515 * @throws MimeTypeParseException |
501 * @throws ClassNotFoundException |
516 * @throws ClassNotFoundException |
502 * @throws NullPointerException if <code>mimeType</code> is null |
517 * @throws NullPointerException if <code>mimeType</code> is null |
503 * |
518 * |
504 * @see tryToLoadClass |
519 * @see #tryToLoadClass |
505 */ |
520 */ |
506 private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException { |
521 private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException { |
507 if (mimeType == null) { |
522 if (mimeType == null) { |
508 throw new NullPointerException("mimeType"); |
523 throw new NullPointerException("mimeType"); |
509 } |
524 } |
1004 if (!mimeType.match(that.mimeType)) { |
1013 if (!mimeType.match(that.mimeType)) { |
1005 return false; |
1014 return false; |
1006 } |
1015 } |
1007 |
1016 |
1008 if ("text".equals(getPrimaryType())) { |
1017 if ("text".equals(getPrimaryType())) { |
1009 if (DataTransferer.doesSubtypeSupportCharset(this) && |
1018 if (DataTransferer.doesSubtypeSupportCharset(this) |
1010 representationClass != null && |
1019 && representationClass != null |
1011 !(isRepresentationClassReader() || |
1020 && !isStandardTextRepresentationClass()) { |
1012 String.class.equals(representationClass) || |
|
1013 isRepresentationClassCharBuffer() || |
|
1014 char[].class.equals(representationClass))) |
|
1015 { |
|
1016 String thisCharset = |
1021 String thisCharset = |
1017 DataTransferer.canonicalName(getParameter("charset")); |
1022 DataTransferer.canonicalName(this.getParameter("charset")); |
1018 String thatCharset = |
1023 String thatCharset = |
1019 DataTransferer.canonicalName(that.getParameter("charset")); |
1024 DataTransferer.canonicalName(that.getParameter("charset")); |
1020 if (thisCharset == null) { |
1025 if (!Objects.equals(thisCharset, thatCharset)) { |
1021 if (thatCharset != null) { |
1026 return false; |
1022 return false; |
|
1023 } |
|
1024 } else { |
|
1025 if (!thisCharset.equals(thatCharset)) { |
|
1026 return false; |
|
1027 } |
|
1028 } |
1027 } |
1029 } |
1028 } |
1030 |
1029 |
1031 if ("html".equals(getSubType()) && |
1030 if ("html".equals(getSubType())) { |
1032 this.getParameter("document") != null ) |
1031 String thisDocument = this.getParameter("document"); |
1033 { |
1032 String thatDocument = that.getParameter("document"); |
1034 if (!this.getParameter("document"). |
1033 if (!Objects.equals(thisDocument, thatDocument)) { |
1035 equals(that.getParameter("document"))) |
|
1036 { |
|
1037 return false; |
1034 return false; |
1038 } |
1035 } |
1039 } |
1036 } |
1040 } |
1037 } |
1041 } |
1038 } |
1088 |
1085 |
1089 // Do not add subType.hashCode() to the total. equals uses |
1086 // Do not add subType.hashCode() to the total. equals uses |
1090 // MimeType.match which reports a match if one or both of the |
1087 // MimeType.match which reports a match if one or both of the |
1091 // subTypes is '*', regardless of the other subType. |
1088 // subTypes is '*', regardless of the other subType. |
1092 |
1089 |
1093 if ("text".equals(primaryType) && |
1090 if ("text".equals(primaryType)) { |
1094 DataTransferer.doesSubtypeSupportCharset(this) && |
1091 if (DataTransferer.doesSubtypeSupportCharset(this) |
1095 representationClass != null && |
1092 && representationClass != null |
1096 !(isRepresentationClassReader() || |
1093 && !isStandardTextRepresentationClass()) { |
1097 String.class.equals(representationClass) || |
1094 String charset = DataTransferer.canonicalName(getParameter("charset")); |
1098 isRepresentationClassCharBuffer() || |
1095 if (charset != null) { |
1099 char[].class.equals(representationClass))) |
1096 total += charset.hashCode(); |
1100 { |
1097 } |
1101 String charset = |
1098 } |
1102 DataTransferer.canonicalName(getParameter("charset")); |
1099 |
1103 if (charset != null) { |
1100 if ("html".equals(getSubType())) { |
1104 total += charset.hashCode(); |
1101 String document = this.getParameter("document"); |
|
1102 if (document != null) { |
|
1103 total += document.hashCode(); |
|
1104 } |
1105 } |
1105 } |
1106 } |
1106 } |
1107 } |
1107 } |
1108 |
1108 |
1109 return total; |
1109 return total; |
1173 private boolean isMimeTypeEqual(MimeType mtype) { |
1173 private boolean isMimeTypeEqual(MimeType mtype) { |
1174 if (this.mimeType == null) { |
1174 if (this.mimeType == null) { |
1175 return (mtype == null); |
1175 return (mtype == null); |
1176 } |
1176 } |
1177 return mimeType.match(mtype); |
1177 return mimeType.match(mtype); |
|
1178 } |
|
1179 |
|
1180 /** |
|
1181 * Checks if the representation class is one of the standard text |
|
1182 * representation classes. |
|
1183 * |
|
1184 * @return true if the representation class is one of the standard text |
|
1185 * representation classes, otherwise false |
|
1186 */ |
|
1187 private boolean isStandardTextRepresentationClass() { |
|
1188 return isRepresentationClassReader() |
|
1189 || String.class.equals(representationClass) |
|
1190 || isRepresentationClassCharBuffer() |
|
1191 || char[].class.equals(representationClass); |
1178 } |
1192 } |
1179 |
1193 |
1180 /** |
1194 /** |
1181 * Does the <code>DataFlavor</code> represent a serialized object? |
1195 * Does the <code>DataFlavor</code> represent a serialized object? |
1182 * @return whether or not a serialized object is represented |
1196 * @return whether or not a serialized object is represented |