DataFlavor provides meta information about data. DataFlavor
is typically used to access data on the clipboard, or during a drag and drop
operation.
An instance of DataFlavor encapsulates a content type as defined in
RFC 2045 and
RFC 2046. A content type is
typically referred to as a MIME type.
A content type consists of a media type (referred to as the primary type), a subtype, and optional parameters. See RFC 2045 for details on the syntax of a MIME type.
The JRE data transfer implementation interprets the parameter
"class" of a MIME type as a representation class. The
representation class reflects the class of the object being transferred. In
other words, the representation class is the type of object returned by
Transferable#getTransferData. For example, the MIME type of
imageFlavor is "image/x-java-image;class=java.awt.Image",
the primary type is image, the subtype is x-java-image, and
the representation class is java.awt.Image. When
getTransferData is invoked with a DataFlavor of
imageFlavor, an instance of java.awt.Image is returned. It's
important to note that DataFlavor does no error checking against the
representation class. It is up to consumers of DataFlavor, such as
Transferable, to honor the representation class.
Note, if you do not specify a representation class when creating a
DataFlavor, the default representation class is used. See appropriate
documentation for DataFlavor's constructors.
Also, DataFlavor instances with the "text" primary MIME
type may have a "charset" parameter. Refer to
RFC 2046 and
selectBestTextFlavor for details on "text" MIME types and
the "charset" parameter.
Equality of DataFlavors is determined by the primary type, subtype,
and representation class. Refer to equals(DataFlavor) for details.
When determining equality, any optional parameters are ignored. For example,
the following produces two DataFlavors that are considered identical:
DataFlavor flavor1 = new DataFlavor(Object.class, "X-test/test; class=<java.lang.Object>; foo=bar"); DataFlavor flavor2 = new DataFlavor(Object.class, "X-test/test; class=<java.lang.Object>; x=y"); // The following returns true. flavor1.equals(flavor2);As mentioned,
flavor1 and flavor2 are considered identical.
As such, asking a Transferable for either DataFlavor returns
the same results.
For more information on using data transfer with Swing see the How to Use Drag and Drop and Data Transfer, section in The Java Tutorial.
| Modifier and Type | Field and Description |
|---|---|
| public static final DataFlavor | allHtmlFlavor
Represents a piece of an HTML markup. |
| pack-priv transient int | |
| public static final DataFlavor | fragmentHtmlFlavor
Represents a piece of an HTML markup. |
| private String | |
| public static final DataFlavor | imageFlavor
The
representationClass = java.awt.Image
mimeType = "image/x-java-image"
|
| public static final DataFlavor | javaFileListFlavor
To transfer a list of files to/from Java (and the underlying platform) a
|
| public static final String | javaJVMLocalObjectMimeType
To transfer a reference to an arbitrary Java object reference that has no
associated MIME Content-type, across a |
| public static final String | javaRemoteObjectMimeType
In order to pass a live link to a Remote object via a Drag and Drop
|
| public static final String | javaSerializedObjectMimeType
A MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent. |
| pack-priv MimeType | |
| public static final DataFlavor | plainTextFlavor
Deprecated
as of 1.3.
The DataFlavor representing plain text with Unicode encoding,
where:
representationClass = InputStream
mimeType = "text/plain; charset=unicode"
|
| private Class | representationClass
Java class of objects this DataFlavor represents. |
| public static final DataFlavor | selectionHtmlFlavor
Represents a piece of an HTML markup. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.2 for interoperability. |
| public static final DataFlavor | stringFlavor
The
representationClass = java.lang.String
mimeType = "application/x-java-serialized-object"
|
| Access | Constructor and Description |
|---|---|
| public | |
| private | DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class<?> representationClass, String humanPresentableName)
Constructs a fully specified |
| public | DataFlavor(Class<?>
the class used to transfer data in this
flavor representationClass, String the human-readable string used to identify
this flavor; if this parameter is humanPresentableName)null then the value of
the MIME Content Type is usedConstructs a |
| public | DataFlavor(String
the string used to identify the MIME type for this
flavor; if the mimeType, String mimeType does not specify a "class="
parameter, or if the class is not successfully loaded, then an
IllegalArgumentException is thrownthe human-readable string used to identify
this flavor; if this parameter is humanPresentableName)null then the value of
the MIME Content Type is usedConstructs a |
| public | DataFlavor(String
the string used to identify the MIME type for this
flavor mimeType, String the human-readable string used to identify
this flavor humanPresentableName, ClassLoader the class loader to use classLoader)Constructs a |
| public | DataFlavor(String
the string used to identify the MIME type for this
flavor; if the class specified by "class=" parameter is not
successfully loaded, then a mimeType)ClassNotFoundException is
thrownConstructs a |
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: a clone of thisDataFlavorOverrides java. Returns a clone of this |
| private static DataFlavor | |
| private static DataFlavor | |
| public boolean | Returns: true if that is equivalent to this
DataFlavor; false otherwisethe o)Object to compare with thisOverrides java. Indicates whether some other object is "equal to" this one. |
| public boolean | Returns: true if that is equivalent to this
DataFlavor; false otherwisethe that)DataFlavor to compare with thisThis method has the same behavior as |
| public boolean | Returns: true if the String (MimeType) is equal; false
otherwise or if s is nullthe s)mimeType to compare
Deprecated
As inconsistent with
hashCode() contract, use
isMimeTypeEqual(String) instead.
Compares only the |
| public final Class | Returns: the default representation classReturns the default representation class. |
| public final String | Returns: the name of the default representation classReturns the name of the default representation class. |
| public String | Returns: the human presentable name for the data format that thisDataFlavor representsReturns the human presentable name for the data format that this
|
| public String | Returns: the MIME type string for this flavorReturns the MIME type string for this |
| public String | Returns: the value of the name parameter, ornull if there is no
associated valuethe parameter name requested paramName)Returns the human presentable name for this |
| public String | Returns: the primary MIME type of thisDataFlavorReturns the primary MIME type for this |
| public Reader | Returns: aReader to read the Transferable's datathe transferable)Transferable whose data will be
requested in this flavorGets a Reader for a text flavor, decoded, if necessary, for the expected charset (encoding). |
| public Class | Returns: theClass which objects supporting this
DataFlavor will return when this DataFlavor is
requestedReturns the |
| public String | Returns: the Sub MIME type of thisDataFlavorReturns the sub MIME type of this |
| public static final DataFlavor | Returns: aDataFlavor representing plain text with Unicode
encodingReturns a
representationClass = java.io.InputStream
mimeType = "text/plain;
charset=<platform default Unicode encoding>"
|
| public int | Returns: a hash code for thisDataFlavorOverrides java. Returns hash code for this |
| private static DataFlavor | |
| private void | initialize(String
the MIME Content Type (must have a class= param) mimeType, String the human Presentable Name or humanPresentableName, ClassLoader nullthe fallback class loader to resolve against classLoader)Common initialization code called from various constructors. |
| public boolean | Returns: true if the DataFlavor specified represents a
java.util.List of java.io.File objectsReturns |
| public boolean | Returns: true if the DataFlavor specified represents a
Remote ObjectReturns |
| public boolean | Returns: true if the DataFlavor specified represents a
Serialized ObjectReturns |
| public boolean | Returns: true if this DataFlavor is a valid text flavor as
described above; false otherwiseReturns whether this |
| public boolean | Returns: true if the string representation of the MIME type passed
in is equivalent to the MIME type of this DataFlavor;
false otherwisethe string representation of the MIME type mimeType)Returns whether the string representation of the MIME type passed in is
equivalent to the MIME type of this |
| public final boolean | Returns: true if the MimeTypes are equal, otherwise
falsethe dataFlavor)DataFlavor to be comparedCompares the |
| private boolean | Returns: true if the MimeTypes are equal, otherwise
falseCompares the |
| public boolean | Returns: whether or not a serialized object is representedDoes the |
| public boolean | Returns: whether or not the representation class for thisDataFlavor is java.nio.ByteBuffer or a subclass
thereofReturns whether the representation class for this |
| public boolean | Returns: whether or not the representation class for thisDataFlavor is java.nio.CharBuffer or a subclass
thereofReturns whether the representation class for this |
| public boolean | Returns: whether or not thisDataFlavor represent a
java.io.InputStreamDoes the |
| public boolean | Returns: whether or not the representation class for thisDataFlavor is java.io.Reader or a subclass
thereofReturns whether the representation class for this |
| public boolean | Returns: true if the representation class is RemoteReturns |
| public boolean | Returns: true if the representation class can be serializedReturns |
| private boolean | Returns: true if the representation class is one of the standard
text representation classes, otherwise falseChecks if the representation class is one of the standard text representation classes. |
| public boolean | Returns: true if that is equivalent to this
DataFlavor; false otherwisethe that)DataFlavor to compare with thisIdentical to |
| protected String | Returns: the mime typethe mime type mimeType)
Deprecated
This method is never invoked by this implementation from 1.1
onwards
Called for each MIME type string to give |
| protected String | Returns: the parameter valuethe parameter name parameterName, String the parameter value parameterValue)
Deprecated
This method is never invoked by this implementation from 1.1
onwards
Called on |
| private String | |
| public synchronized void | readExternal(ObjectInput is)
Implements java. Restores this |
| public static final DataFlavor | Returns: the best (highest fidelity) flavor according to the rules specified above, ornull, if availableFlavors is
null, has zero length, or contains no text flavorsan array of available availableFlavors)DataFlavorsSelects the best text |
| public void | setHumanPresentableName(String
the new human presentable name humanPresentableName)Sets the human presentable name for the data format that this
|
| public String | Returns: string representation of thisDataFlavorOverrides java. String representation of this |
| protected static final Class | Returns: the class loadedthe name of the class to be loaded className, ClassLoader the fallback loader fallback)Tries to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified. |
| public synchronized void | writeExternal(ObjectOutput os)
Implements java. Serializes this |
| allHtmlFlavor | back to summary |
|---|---|
| public static final DataFlavor allHtmlFlavor Represents a piece of an HTML markup. If possible, the markup received
from a native system is supplemented with additional tags to make up a
well-formed HTML document. If the flavor is used to represent the data in
a
representationClass = String
mimeType = "text/html"
| |
| atom | back to summary |
|---|---|
| pack-priv transient int atom | |
| fragmentHtmlFlavor | back to summary |
|---|---|
| public static final DataFlavor fragmentHtmlFlavor Represents a piece of an HTML markup. If possible, the markup received
from a native system is supplemented with pair tags to be a well-formed
HTML markup. If the flavor is used to represent the data in a
representationClass = String
mimeType = "text/html"
| |
| humanPresentableName | back to summary |
|---|---|
| private String humanPresentableName | |
| imageFlavor | back to summary |
|---|---|
| public static final DataFlavor imageFlavor The
representationClass = java.awt.Image
mimeType = "image/x-java-image"
Will be null if java.awt.Image is not visible, the
java.desktop module is not loaded, or the java.desktop
module is not in the run-time image.
| |
| javaFileListFlavor | back to summary |
|---|---|
| public static final DataFlavor javaFileListFlavor To transfer a list of files to/from Java (and the underlying platform) a
| |
| javaJVMLocalObjectMimeType | back to summary |
|---|---|
| public static final String javaJVMLocalObjectMimeType To transfer a reference to an arbitrary Java object reference that has no
associated MIME Content-type, across a
The object reference returned from | |
| javaRemoteObjectMimeType | back to summary |
|---|---|
| public static final String javaRemoteObjectMimeType In order to pass a live link to a Remote object via a Drag and Drop
| |
| javaSerializedObjectMimeType | back to summary |
|---|---|
| public static final String javaSerializedObjectMimeType A MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent.
The representation class associated with this | |
| mimeType | back to summary |
|---|---|
| pack-priv MimeType mimeType | |
| plainTextFlavor | back to summary |
|---|---|
| public static final DataFlavor plainTextFlavor
Deprecated as of 1.3. Use The
representationClass = InputStream
mimeType = "text/plain; charset=unicode"
This DataFlavor has been deprecated because:
| |
| representationClass | back to summary |
|---|---|
| private Class<?> representationClass Java class of objects this DataFlavor represents. | |
| selectionHtmlFlavor | back to summary |
|---|---|
| public static final DataFlavor selectionHtmlFlavor Represents a piece of an HTML markup. The markup consists of the part
selected on the source side. Therefore some tags in the markup may be
unpaired. If the flavor is used to represent the data in a
representationClass = String
mimeType = "text/html"
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.2 for interoperability. | |
| stringFlavor | back to summary |
|---|---|
| public static final DataFlavor stringFlavor The
representationClass = java.lang.String
mimeType = "application/x-java-serialized-object"
| |
| DataFlavor | back to summary |
|---|---|
| public DataFlavor() Constructs a new
| |
| DataFlavor | back to summary |
|---|---|
| private DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class<?> representationClass, String humanPresentableName) Constructs a fully specified
| |
| DataFlavor | back to summary |
|---|---|
| public DataFlavor(Class<?> representationClass, String humanPresentableName) Constructs a
The returned representationClass = representationClass mimeType = application/x-java-serialized-object
| |
| DataFlavor | back to summary |
|---|---|
| public DataFlavor(String mimeType, String humanPresentableName) Constructs a
The returned
If the Otherwise:
representationClass = InputStream
mimeType = mimeType
| |
| DataFlavor | back to summary |
|---|---|
| public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException Constructs a
The returned
If the mimeType is
"application/x-java-serialized-object; class=<representation class>",
the result is the same as calling
Otherwise:
representationClass = InputStream
mimeType = mimeType
| |
| DataFlavor | back to summary |
|---|---|
| public DataFlavor(String mimeType) throws ClassNotFoundException Constructs a
| |
| clone | back to summary |
|---|---|
| public Object clone() throws CloneNotSupportedException Overrides java. Returns a clone of this
| |
| createConstant | back to summary |
|---|---|
| private static DataFlavor createConstant(Class<?> rc, String prn) | |
| createConstant | back to summary |
|---|---|
| private static DataFlavor createConstant(String mt, String prn) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
The equals comparison for the
| |
| equals | back to summary |
|---|---|
| public boolean equals(DataFlavor that) This method has the same behavior as
| |
| equals | back to summary |
|---|---|
| public boolean equals(String s)
Deprecated As inconsistent with Compares only the
| |
| getDefaultRepresentationClass | back to summary |
|---|---|
| public final Class Returns the default representation class.
| |
| getDefaultRepresentationClassAsString | back to summary |
|---|---|
| public final String getDefaultRepresentationClassAsString() Returns the name of the default representation class.
| |
| getHumanPresentableName | back to summary |
|---|---|
| public String getHumanPresentableName() Returns the human presentable name for the data format that this
| |
| getMimeType | back to summary |
|---|---|
| public String getMimeType() Returns the MIME type string for this
| |
| getParameter | back to summary |
|---|---|
| public String getParameter(String paramName) Returns the human presentable name for this | |
| getPrimaryType | back to summary |
|---|---|
| public String getPrimaryType() Returns the primary MIME type for this
| |
| getReaderForText | back to summary |
|---|---|
| public Reader getReaderForText(Transferable transferable) throws UnsupportedFlavorException, IOException Gets a Reader for a text flavor, decoded, if necessary, for the expected
charset (encoding). The supported representation classes are
Because text flavors which do not support the charset parameter are
encoded in a non-standard format, this method should not be called for
such flavors. However, in order to maintain backward-compatibility, if
this method is called for such a flavor, this method will treat the
flavor as though it supports the charset parameter and attempt to decode
it accordingly. See
| |
| getRepresentationClass | back to summary |
|---|---|
| public Class Returns the
| |
| getSubType | back to summary |
|---|---|
| public String getSubType() Returns the sub MIME type of this
| |
| getTextPlainUnicodeFlavor | back to summary |
|---|---|
| public static final DataFlavor getTextPlainUnicodeFlavor() Returns a
representationClass = java.io.InputStream
mimeType = "text/plain;
charset=<platform default Unicode encoding>"
Implementation Note Oracle's implementation for Microsoft Windows and macOS uses
the encoding
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns hash code for this
| |
| initHtml | back to summary |
|---|---|
| private static DataFlavor initHtml(String htmlFlavorType) | |
| initialize | back to summary |
|---|---|
| private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException Common initialization code called from various constructors.
| |
| isFlavorJavaFileListType | back to summary |
|---|---|
| public boolean isFlavorJavaFileListType() Returns
| |
| isFlavorRemoteObjectType | back to summary |
|---|---|
| public boolean isFlavorRemoteObjectType() Returns
| |
| isFlavorSerializedObjectType | back to summary |
|---|---|
| public boolean isFlavorSerializedObjectType() Returns
| |
| isFlavorTextType | back to summary |
|---|---|
| public boolean isFlavorTextType() Returns whether this
If this flavor supports the charset parameter, it must be equivalent to
If this flavor does not support the charset parameter, its representation
must be
See
| |
| isMimeTypeEqual | back to summary |
|---|---|
| public boolean isMimeTypeEqual(String mimeType) Returns whether the string representation of the MIME type passed in is
equivalent to the MIME type of this
| |
| isMimeTypeEqual | back to summary |
|---|---|
| public final boolean isMimeTypeEqual(DataFlavor dataFlavor) Compares the
| |
| isMimeTypeEqual | back to summary |
|---|---|
| private boolean isMimeTypeEqual(MimeType mtype) Compares the
| |
| isMimeTypeSerializedObject | back to summary |
|---|---|
| public boolean isMimeTypeSerializedObject() Does the
| |
| isRepresentationClassByteBuffer | back to summary |
|---|---|
| public boolean isRepresentationClassByteBuffer() Returns whether the representation class for this
| |
| isRepresentationClassCharBuffer | back to summary |
|---|---|
| public boolean isRepresentationClassCharBuffer() Returns whether the representation class for this
| |
| isRepresentationClassInputStream | back to summary |
|---|---|
| public boolean isRepresentationClassInputStream() Does the
| |
| isRepresentationClassReader | back to summary |
|---|---|
| public boolean isRepresentationClassReader() Returns whether the representation class for this
| |
| isRepresentationClassRemote | back to summary |
|---|---|
| public boolean isRepresentationClassRemote() Returns
| |
| isRepresentationClassSerializable | back to summary |
|---|---|
| public boolean isRepresentationClassSerializable() Returns
| |
| isStandardTextRepresentationClass | back to summary |
|---|---|
| private boolean isStandardTextRepresentationClass() Checks if the representation class is one of the standard text representation classes.
| |
| match | back to summary |
|---|---|
| public boolean match(DataFlavor that) Identical to
| |
| normalizeMimeType | back to summary |
|---|---|
| protected String normalizeMimeType(String mimeType)
Deprecated This method is never invoked by this implementation from 1.1 onwards Called for each MIME type string to give | |
| normalizeMimeTypeParameter | back to summary |
|---|---|
| protected String normalizeMimeTypeParameter(String parameterName, String parameterValue)
Deprecated This method is never invoked by this implementation from 1.1 onwards Called on
This method is called for each parameter name/value pair and should
return the normalized representation of the
| |
| paramString | back to summary |
|---|---|
| private String paramString() | |
| readExternal | back to summary |
|---|---|
| public synchronized void readExternal(ObjectInput is) throws IOException, ClassNotFoundException Implements java. Restores this
| |
| selectBestTextFlavor | back to summary |
|---|---|
| public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors) Selects the best text Flavors are first sorted by their MIME types in the following order:
For example, "text/sgml" will be selected over "text/html", and
If two or more flavors share the best MIME type in the array, then that MIME type will be checked to see if it supports the charset parameter. The following MIME types support, or are treated as though they support, the charset parameter:
DataFlavor which uses that MIME type. If so, the JRE will assume
from that point on that the MIME type supports the charset parameter and
will not check again. If the parameter is not explicitly listed, the JRE
will assume from that point on that the MIME type does not support the
charset parameter and will not check again. Because this check is
performed on an arbitrarily chosen DataFlavor, developers must
ensure that all DataFlavors with a "text/<other>" MIME type
specify the charset parameter if it is supported by that MIME type.
Developers should never rely on the JRE to substitute the platform's
default charset for a "text/<other>" DataFlavor. Failure to adhere
to this restriction will lead to undefined behavior.
If the best MIME type in the array does not support the charset
parameter, the flavors which share that MIME type will then be sorted by
their representation classes in the following order:
If two or more flavors share the best representation class, or if no flavor has one of the three specified representations, then one of those flavors will be chosen non-deterministically.
If the best MIME type in the array does support the charset parameter,
the flavors which share that MIME type will then be sorted by their
representation classes in the following order: If two or more flavors share the best representation class, and that representation is one of the four explicitly listed, then one of those flavors will be chosen non-deterministically. If, however, no flavor has one of the four specified representations, the flavors will then be sorted by their charsets. Unicode charsets, such as "UTF-16", "UTF-8", "UTF-16BE", "UTF-16LE", and their aliases, are considered best. After them, the platform default charset and its aliases are selected. "US-ASCII" and its aliases are worst. All other charsets are chosen in alphabetical order, but only charsets supported by this implementation of the Java platform will be considered.
If two or more flavors share the best charset, the flavors will then
again be sorted by their representation classes in the following order:
If two or more flavors share the best representation class, or if no flavor has one of the three specified representations, then one of those flavors will be chosen non-deterministically.
| |
| setHumanPresentableName | back to summary |
|---|---|
| public void setHumanPresentableName(String humanPresentableName) Sets the human presentable name for the data format that this
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. String representation of this
| |
| tryToLoadClass | back to summary |
|---|---|
| protected static final Class Tries to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified.
| |
| writeExternal | back to summary |
|---|---|
| public synchronized void writeExternal(ObjectOutput os) throws IOException Implements java. Serializes this
| |