📄 dataflavor.java
字号:
* <code>java.lang.String</code>, <code>java.nio.CharBuffer</code>, or * <code>[C</code>, the <code>charset</code> parameter must also be equal. * If a charset is not explicitly specified for one or both * <code>DataFlavor</code>s, the platform default encoding is assumed. See * <code>selectBestTextFlavor</code> for a list of text flavors which * support the charset parameter. * * @param that the <code>DataFlavor</code> to compare with * <code>this</code> * @return <code>true</code> if <code>that</code> is equivalent to this * <code>DataFlavor</code>; <code>false</code> otherwise * @see #selectBestTextFlavor */ public boolean match(DataFlavor that) { return equals(that); } /** * Returns whether the string representation of the MIME type passed in * is equivalent to the MIME type of this <code>DataFlavor</code>. * Parameters are not included in the comparison. * * @param mimeType the string representation of the MIME type * @return true if the string representation of the MIME type passed in is * equivalent to the MIME type of this <code>DataFlavor</code>; * false otherwise * @throws NullPointerException if mimeType is <code>null</code> */ public boolean isMimeTypeEqual(String mimeType) { // JCK Test DataFlavor0117: if 'mimeType' is null, throw NPE if (mimeType == null) { throw new NullPointerException("mimeType"); } if (this.mimeType == null) { return false; } try { return this.mimeType.match(new MimeType(mimeType)); } catch (MimeTypeParseException mtpe) { return false; } } /** * Compares the <code>mimeType</code> of two <code>DataFlavor</code> * objects. No parameters are considered. * * @param dataFlavor the <code>DataFlavor</code> to be compared * @return true if the <code>MimeType</code>s are equal, * otherwise false */ public final boolean isMimeTypeEqual(DataFlavor dataFlavor) { return isMimeTypeEqual(dataFlavor.mimeType); } /** * Compares the <code>mimeType</code> of two <code>DataFlavor</code> * objects. No parameters are considered. * * @return true if the <code>MimeType</code>s are equal, * otherwise false */ private boolean isMimeTypeEqual(MimeType mtype) { if (this.mimeType == null) { return (mtype == null); } return mimeType.match(mtype); } /** * Does the <code>DataFlavor</code> represent a serialized object? */ public boolean isMimeTypeSerializedObject() { return isMimeTypeEqual(javaSerializedObjectMimeType); } public final Class getDefaultRepresentationClass() { return ioInputStreamClass; } public final String getDefaultRepresentationClassAsString() { return getDefaultRepresentationClass().getName(); } /** * Does the <code>DataFlavor</code> represent a * <code>java.io.InputStream</code>? */ public boolean isRepresentationClassInputStream() { return ioInputStreamClass.isAssignableFrom(representationClass); } /** * Returns whether the representation class for this * <code>DataFlavor</code> is <code>java.io.Reader</code> or a subclass * thereof. * * @since 1.4 */ public boolean isRepresentationClassReader() { return java.io.Reader.class.isAssignableFrom(representationClass); } /** * Returns whether the representation class for this * <code>DataFlavor</code> is <code>java.nio.CharBuffer</code> or a * subclass thereof. * * @since 1.4 */ public boolean isRepresentationClassCharBuffer() { return java.nio.CharBuffer.class.isAssignableFrom(representationClass); } /** * Returns whether the representation class for this * <code>DataFlavor</code> is <code>java.nio.ByteBuffer</code> or a * subclass thereof. * * @since 1.4 */ public boolean isRepresentationClassByteBuffer() { return java.nio.ByteBuffer.class.isAssignableFrom(representationClass); } /** * Returns true if the representation class can be serialized. * @return true if the representation class can be serialized */ public boolean isRepresentationClassSerializable() { return java.io.Serializable.class.isAssignableFrom(representationClass); } /** * Returns true if the representation class is <code>Remote</code>. * @return true if the representation class is <code>Remote</code> */ public boolean isRepresentationClassRemote() { return java.rmi.Remote.class.isAssignableFrom(representationClass); } /** * Returns true if the <code>DataFlavor</code> specified represents * a serialized object. * @return true if the <code>DataFlavor</code> specified represents * a Serialized Object */ public boolean isFlavorSerializedObjectType() { return isRepresentationClassSerializable() && isMimeTypeEqual(javaSerializedObjectMimeType); } /** * Returns true if the <code>DataFlavor</code> specified represents * a remote object. * @return true if the <code>DataFlavor</code> specified represents * a Remote Object */ public boolean isFlavorRemoteObjectType() { return isRepresentationClassRemote() && isRepresentationClassSerializable() && isMimeTypeEqual(javaRemoteObjectMimeType); } /** * Returns true if the <code>DataFlavor</code> specified represents * a list of file objects. * @return true if the <code>DataFlavor</code> specified represents * a List of File objects */ public boolean isFlavorJavaFileListType() { if (mimeType == null || representationClass == null) return false; return java.util.List.class.isAssignableFrom(representationClass) && mimeType.match(javaFileListFlavor.mimeType); } /** * Returns whether this <code>DataFlavor</code> is a valid text flavor for * this implementation of the Java platform. Only flavors equivalent to * <code>DataFlavor.stringFlavor</code> and <code>DataFlavor</code>s with * a primary MIME type of "text" can be valid text flavors. * <p> * If this flavor supports the charset parameter, it must be equivalent to * <code>DataFlavor.stringFlavor</code>, or its representation must be * <code>java.io.Reader</code>, <code>java.lang.String</code>, * <code>java.nio.CharBuffer</code>, <code>[C</code>, * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or * <code>[B</code>. If the representation is * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>, or * <code>[B</code>, then this flavor's <code>charset</code> parameter must * be supported by this implementation of the Java platform. If a charset * is not specified, then the platform default charset, which is always * supported, is assumed. * <p> * If this flavor does not support the charset parameter, its * representation must be <code>java.io.InputStream</code>, * <code>java.nio.ByteBuffer</code>, or <code>[B</code>. * <p> * See <code>selectBestTextFlavor</code> for a list of text flavors which * support the charset parameter. * * @return <code>true</code> if this <code>DataFlavor</code> is a valid * 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>. */ public synchronized void writeExternal(ObjectOutput os) throws IOException { if (mimeType != null) { mimeType.setParameter("humanPresentableName", humanPresentableName); os.writeObject(mimeType); mimeType.removeParameter("humanPresentableName"); } else { os.writeObject(null); } os.writeObject(representationClass); } /** * Restores this <code>DataFlavor</code> from a Serialized state. */ public synchronized void readExternal(ObjectInput is) throws IOException , ClassNotFoundException { String rcn = null; mimeType = (MimeType)is.readObject(); if (mimeType != null) { humanPresentableName = mimeType.getParameter("humanPresentableName"); mimeType.removeParameter("humanPresentableName"); rcn = mimeType.getParameter("class"); if (rcn == null) { throw new IOException("no class parameter specified in: " + mimeType); } } try { representationClass = (Class)is.readObject(); } catch (OptionalDataException ode) { if (rcn != null) { representationClass = DataFlavor.tryToLoadClass(rcn, getClass().getClassLoader()); } } } /** * Returns a clone of this <code>DataFlavor</code>. * @return a clone of this <code>DataFlavor</code> */ public Object clone() throws CloneNotSupportedException { Object newObj = super.clone(); if (mimeType != null) { ((DataFlavor)newObj).mimeType = (MimeType)mimeType.clone(); } return newObj; } // clone() /** * Called on <code>DataFlavor</code> for every MIME Type parameter * to allow <code>DataFlavor</code> subclasses to handle special * parameters like the text/plain <code>charset</code> * parameters, whose values are case insensitive. (MIME type parameter * values are supposed to be case sensitive. * <p> * This method is called for each parameter name/value pair and should * return the normalized representation of the <code>parameterValue</code>. * * This method is never invoked by this implementation from 1.1 onwards. * * @deprecated */ protected String normalizeMimeTypeParameter(String parameterName, String parameterValue) { return parameterValue; } /** * Called for each MIME type string to give <code>DataFlavor</code> subtypes * the opportunity to change how the normalization of MIME types is * accomplished. One possible use would be to add default * parameter/value pairs in cases where none are present in the MIME * type string passed in. * * This method is never invoked by this implementation from 1.1 onwards. * * @deprecated */ protected String normalizeMimeType(String mimeType) { return mimeType; } /* * fields */ /* placeholder for caching any platform-specific data for flavor */ transient int atom; /* Mime Type of DataFlavor */ MimeType mimeType; private String humanPresentableName; /** Java class of objects this DataFlavor represents **/ private Class representationClass;} // class DataFlavor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -