APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.datatransfer

public Class DataFlavor

extends Object
implements Externalizable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Externalizable, java.io.Serializable
Imports
java.io.ByteArrayInputStream, .CharArrayReader, .Externalizable, .IOException, .InputStream, .InputStreamReader, .ObjectInput, .ObjectOutput, .OptionalDataException, .Reader, .Serial, .StringReader, .UnsupportedEncodingException, java.nio.ByteBuffer, .CharBuffer, java.util.Arrays, .Collections, .Objects, sun.datatransfer.DataFlavorUtil

A 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.

Authors
Blake Sullivan, Laurence P. G. Cable, Jeff Dunn
Since
1.1

Field Summary

Modifier and TypeField 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 DataFlavor representing a Java Image class, where:

    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 DataFlavor of this type/subtype and representation class of java.util.List is used.

public static final String
javaJVMLocalObjectMimeType

To transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across a Transferable interface WITHIN THE SAME JVM, a DataFlavor with this type/subtype is used, with a representationClass equal to the type of the class/interface being passed across the Transferable.

public static final String
javaRemoteObjectMimeType

In order to pass a live link to a Remote object via a Drag and Drop ACTION_LINK operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of the DataFlavor represents the type of the Remote interface to be transferred.

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 DataFlavor representing a Java Unicode String class, where:

    representationClass = java.lang.String
    mimeType            = "application/x-java-serialized-object"

Constructor Summary

AccessConstructor and Description
public
DataFlavor()

Constructs a new DataFlavor.

private
DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class<?> representationClass, String humanPresentableName)

Constructs a fully specified DataFlavor.

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 null then the value of the MIME Content Type is used
humanPresentableName
)

Constructs a DataFlavor that represents a Java class.

public
DataFlavor(String
the string used to identify the MIME type for this flavor; if the mimeType does not specify a "class=" parameter, or if the class is not successfully loaded, then an IllegalArgumentException is thrown
mimeType
,
String
the human-readable string used to identify this flavor; if this parameter is null then the value of the MIME Content Type is used
humanPresentableName
)

Constructs a DataFlavor that represents a MimeType.

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 DataFlavor that represents a MimeType.

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 ClassNotFoundException is thrown
mimeType
)

Constructs a DataFlavor from a mimeType string.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

a clone of this DataFlavor
clone
()

Overrides java.lang.Object.clone.

Returns a clone of this DataFlavor.

private static DataFlavor
private static DataFlavor
public boolean

Returns:

true if that is equivalent to this DataFlavor; false otherwise
equals
(Object
the Object to compare with this
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean

Returns:

true if that is equivalent to this DataFlavor; false otherwise
equals
(DataFlavor
the DataFlavor to compare with this
that
)

This method has the same behavior as equals(Object).

public boolean

Returns:

true if the String (MimeType) is equal; false otherwise or if s is null
equals
(String
the mimeType to compare
s
)
Deprecated As inconsistent with hashCode() contract, use isMimeTypeEqual(String) instead.

Compares only the mimeType against the passed in String and representationClass is not considered in the comparison.

public final Class<?>

Returns:

the default representation class
getDefaultRepresentationClass
()

Returns the default representation class.

public final String

Returns:

the name of the default representation class
getDefaultRepresentationClassAsString
()

Returns the name of the default representation class.

public String

Returns:

the human presentable name for the data format that this DataFlavor represents
getHumanPresentableName
()

Returns the human presentable name for the data format that this DataFlavor represents.

public String

Returns:

the MIME type string for this flavor
getMimeType
()

Returns the MIME type string for this DataFlavor.

public String

Returns:

the value of the name parameter, or null if there is no associated value
getParameter
(String
the parameter name requested
paramName
)

Returns the human presentable name for this DataFlavor if paramName equals "humanPresentableName".

public String

Returns:

the primary MIME type of this DataFlavor
getPrimaryType
()

Returns the primary MIME type for this DataFlavor.

public Reader

Returns:

a Reader to read the Transferable's data
getReaderForText
(Transferable
the Transferable whose data will be requested in this flavor
transferable
)

Gets a Reader for a text flavor, decoded, if necessary, for the expected charset (encoding).

public Class<?>

Returns:

the Class which objects supporting this DataFlavor will return when this DataFlavor is requested
getRepresentationClass
()

Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.

public String

Returns:

the Sub MIME type of this DataFlavor
getSubType
()

Returns the sub MIME type of this DataFlavor.

public static final DataFlavor

Returns:

a DataFlavor representing plain text with Unicode encoding
getTextPlainUnicodeFlavor
()

Returns a DataFlavor representing plain text with Unicode encoding, where:

    representationClass = java.io.InputStream
    mimeType            = "text/plain;
                           charset=<platform default Unicode encoding>"
public int

Returns:

a hash code for this DataFlavor
hashCode
()

Overrides java.lang.Object.hashCode.

Returns hash code for this DataFlavor.

private static DataFlavor
initHtml(String htmlFlavorType)

private void
initialize(String
the MIME Content Type (must have a class= param)
mimeType
,
String
the human Presentable Name or null
humanPresentableName
,
ClassLoader
the 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 objects
isFlavorJavaFileListType
()

Returns true if the DataFlavor specified represents a list of file objects.

public boolean

Returns:

true if the DataFlavor specified represents a Remote Object
isFlavorRemoteObjectType
()

Returns true if the DataFlavor specified represents a remote object.

public boolean

Returns:

true if the DataFlavor specified represents a Serialized Object
isFlavorSerializedObjectType
()

Returns true if the DataFlavor specified represents a serialized object.

public boolean

Returns:

true if this DataFlavor is a valid text flavor as described above; false otherwise
isFlavorTextType
()

Returns whether this DataFlavor is a valid text flavor for this implementation of the Java platform.

public boolean

Returns:

true if the string representation of the MIME type passed in is equivalent to the MIME type of this DataFlavor; false otherwise
isMimeTypeEqual
(String
the 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 DataFlavor.

public final boolean

Returns:

true if the MimeTypes are equal, otherwise false
isMimeTypeEqual
(DataFlavor
the DataFlavor to be compared
dataFlavor
)

Compares the mimeType of two DataFlavor objects.

private boolean

Returns:

true if the MimeTypes are equal, otherwise false
isMimeTypeEqual
(MimeType mtype)

Compares the mimeType of two DataFlavor objects.

public boolean

Returns:

whether or not a serialized object is represented
isMimeTypeSerializedObject
()

Does the DataFlavor represent a serialized object?

public boolean

Returns:

whether or not the representation class for this DataFlavor is java.nio.ByteBuffer or a subclass thereof
isRepresentationClassByteBuffer
()

Returns whether the representation class for this DataFlavor is java.nio.ByteBuffer or a subclass thereof.

public boolean

Returns:

whether or not the representation class for this DataFlavor is java.nio.CharBuffer or a subclass thereof
isRepresentationClassCharBuffer
()

Returns whether the representation class for this DataFlavor is java.nio.CharBuffer or a subclass thereof.

public boolean

Returns:

whether or not this DataFlavor represent a java.io.InputStream
isRepresentationClassInputStream
()

Does the DataFlavor represent a java.io.InputStream?

public boolean

Returns:

whether or not the representation class for this DataFlavor is java.io.Reader or a subclass thereof
isRepresentationClassReader
()

Returns whether the representation class for this DataFlavor is java.io.Reader or a subclass thereof.

public boolean

Returns:

true if the representation class is Remote
isRepresentationClassRemote
()

Returns true if the representation class is Remote.

public boolean

Returns:

true if the representation class can be serialized
isRepresentationClassSerializable
()

Returns true if the representation class can be serialized.

private boolean

Returns:

true if the representation class is one of the standard text representation classes, otherwise false
isStandardTextRepresentationClass
()

Checks if the representation class is one of the standard text representation classes.

public boolean

Returns:

true if that is equivalent to this DataFlavor; false otherwise
match
(DataFlavor
the DataFlavor to compare with this
that
)

Identical to equals(DataFlavor).

protected String

Returns:

the mime type
normalizeMimeType
(String
the mime type
mimeType
)
Deprecated This method is never invoked by this implementation from 1.1 onwards

Called for each MIME type string to give DataFlavor subtypes the opportunity to change how the normalization of MIME types is accomplished.

protected String

Returns:

the parameter value
normalizeMimeTypeParameter
(String
the parameter name
parameterName
,
String
the parameter value
parameterValue
)
Deprecated This method is never invoked by this implementation from 1.1 onwards

Called on DataFlavor for every MIME Type parameter to allow DataFlavor subclasses to handle special parameters like the text/plain charset parameters, whose values are case insensitive.

private String
public synchronized void
readExternal(ObjectInput is)

Implements java.io.Externalizable.readExternal.

Restores this DataFlavor from a Serialized state.

public static final DataFlavor

Returns:

the best (highest fidelity) flavor according to the rules specified above, or null, if availableFlavors is null, has zero length, or contains no text flavors
selectBestTextFlavor
(DataFlavor[]
an array of available DataFlavors
availableFlavors
)

Selects the best text DataFlavor from an array of DataFlavors.

public void
setHumanPresentableName(String
the new human presentable name
humanPresentableName
)

Sets the human presentable name for the data format that this DataFlavor represents.

public String

Returns:

string representation of this DataFlavor
toString
()

Overrides java.lang.Object.toString.

String representation of this DataFlavor and its parameters.

protected static final Class<?>

Returns:

the class loaded
tryToLoadClass
(String
the 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.io.Externalizable.writeExternal.

Serializes this DataFlavor.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

allHtmlFlavorback 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 Transferable instance, no additional changes will be made.

    representationClass = String
    mimeType            = "text/html"
Since
1.8
atomback to summary
pack-priv transient int atom
fragmentHtmlFlavorback 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 Transferable instance, no additional changes will be made.

    representationClass = String
    mimeType            = "text/html"
Since
1.8
humanPresentableNameback to summary
private String humanPresentableName
imageFlavorback to summary
public static final DataFlavor imageFlavor

The DataFlavor representing a Java Image class, where:

    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.
javaFileListFlavorback to summary
public static final DataFlavor javaFileListFlavor

To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.

javaJVMLocalObjectMimeTypeback 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 Transferable interface WITHIN THE SAME JVM, a DataFlavor with this type/subtype is used, with a representationClass equal to the type of the class/interface being passed across the Transferable.

The object reference returned from Transferable.getTransferData for a DataFlavor with this MIME Content-Type is required to be an instance of the representation Class of the DataFlavor.

javaRemoteObjectMimeTypeback to summary
public static final String javaRemoteObjectMimeType

In order to pass a live link to a Remote object via a Drag and Drop ACTION_LINK operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of the DataFlavor represents the type of the Remote interface to be transferred.

javaSerializedObjectMimeTypeback 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 DataFlavor identifies the Java type of an object returned as a reference from an invocation java.awt.datatransfer.getTransferData.

mimeTypeback to summary
pack-priv MimeType mimeType
plainTextFlavorback to summary
public static final DataFlavor plainTextFlavor

Deprecated

as of 1.3. Use getReaderForText instead of Transferable.getTransferData(DataFlavor.plainTextFlavor).

The DataFlavor representing plain text with Unicode encoding, where:

    representationClass = InputStream
    mimeType            = "text/plain; charset=unicode"
This DataFlavor has been deprecated because:
  • Its representation is an InputStream, an 8-bit based representation, while Unicode is a 16-bit character set
  • The charset "unicode" is not well-defined. "unicode" implies a particular platform's implementation of Unicode, not a cross-platform implementation
Annotations
@Deprecated
representationClassback to summary
private Class<?> representationClass

Java class of objects this DataFlavor represents.

selectionHtmlFlavorback 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 Transferable instance, no additional changes will be made. This DataFlavor instance represents the same HTML markup as DataFlavor instances which content MIME type does not contain document parameter and representation class is the String class.

    representationClass = String
    mimeType            = "text/html"
Since
1.8
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.2 for interoperability.

Annotations
@Serial
stringFlavorback to summary
public static final DataFlavor stringFlavor

The DataFlavor representing a Java Unicode String class, where:

    representationClass = java.lang.String
    mimeType            = "application/x-java-serialized-object"

Constructor Detail

DataFlavorback to summary
public DataFlavor()

Constructs a new DataFlavor. This constructor is provided only for the purpose of supporting the Externalizable interface. It is not intended for public (client) use.

Since
1.2
DataFlavorback to summary
private DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class<?> representationClass, String humanPresentableName)

Constructs a fully specified DataFlavor.

Exceptions
NullPointerException:
if either primaryType, subType or representationClass is null
DataFlavorback to summary
public DataFlavor(Class<?> representationClass, String humanPresentableName)

Constructs a DataFlavor that represents a Java class.

The returned DataFlavor will have the following characteristics:

   representationClass = representationClass
   mimeType            = application/x-java-serialized-object
Parameters
representationClass:Class<?>

the class used to transfer data in this flavor

humanPresentableName:String

the human-readable string used to identify this flavor; if this parameter is null then the value of the MIME Content Type is used

Exceptions
NullPointerException:
if representationClass is null
DataFlavorback to summary
public DataFlavor(String mimeType, String humanPresentableName)

Constructs a DataFlavor that represents a MimeType.

The returned DataFlavor will have the following characteristics:

If the mimeType is "application/x-java-serialized-object; class=<representation class>", the result is the same as calling new DataFlavor(Class.forName(<representation class>).

Otherwise:

    representationClass = InputStream
    mimeType            = mimeType
Parameters
mimeType:String

the string used to identify the MIME type for this flavor; if the mimeType does not specify a "class=" parameter, or if the class is not successfully loaded, then an IllegalArgumentException is thrown

humanPresentableName:String

the human-readable string used to identify this flavor; if this parameter is null then the value of the MIME Content Type is used

Exceptions
IllegalArgumentException:
if mimeType is invalid or if the class is not successfully loaded
NullPointerException:
if mimeType is null
DataFlavorback to summary
public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException

Constructs a DataFlavor that represents a MimeType.

The returned DataFlavor will have the following characteristics:

If the mimeType is "application/x-java-serialized-object; class=<representation class>", the result is the same as calling new DataFlavor(Class.forName(<representation class>).

Otherwise:

    representationClass = InputStream
    mimeType            = mimeType
Parameters
mimeType:String

the string used to identify the MIME type for this flavor

humanPresentableName:String

the human-readable string used to identify this flavor

classLoader:ClassLoader

the class loader to use

Exceptions
ClassNotFoundException:
if the class is not loaded
IllegalArgumentException:
if mimeType is invalid
NullPointerException:
if mimeType is null
DataFlavorback to summary
public DataFlavor(String mimeType) throws ClassNotFoundException

Constructs a DataFlavor from a mimeType string. The string can specify a "class=<fully specified Java class name>" parameter to create a DataFlavor with the desired representation class. If the string does not contain "class=" parameter, java.io.InputStream is used as default.

Parameters
mimeType: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 ClassNotFoundException is thrown

Exceptions
ClassNotFoundException:
if the class is not loaded
IllegalArgumentException:
if mimeType is invalid
NullPointerException:
if mimeType is null

Method Detail

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Returns a clone of this DataFlavor.

Returns:Object

a clone of this DataFlavor

Exceptions
CloneNotSupportedException:

Doc from java.lang.Object.clone.

if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

createConstantback to summary
private static DataFlavor createConstant(Class<?> rc, String prn)
createConstantback to summary
private static DataFlavor createConstant(String mt, String prn)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

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 DataFlavor class is implemented as follows: Two DataFlavors are considered equal if and only if their MIME primary type and subtype and representation class are equal. Additionally, if the primary type is "text", the subtype denotes a text flavor which supports the charset parameter, and the representation class is not java.io.Reader, java.lang.String, java.nio.CharBuffer, or [C, the charset parameter must also be equal. If a charset is not explicitly specified for one or both DataFlavors, the platform default encoding is assumed. See selectBestTextFlavor for a list of text flavors which support the charset parameter.

Parameters
o:Object

the Object to compare with this

Returns:boolean

true if that is equivalent to this DataFlavor; false otherwise

See Also
selectBestTextFlavor
equalsback to summary
public boolean equals(DataFlavor that)

This method has the same behavior as equals(Object). The only difference being that it takes a DataFlavor instance as a parameter.

Parameters
that:DataFlavor

the DataFlavor to compare with this

Returns:boolean

true if that is equivalent to this DataFlavor; false otherwise

See Also
selectBestTextFlavor
equalsback to summary
public boolean equals(String s)

Deprecated

As inconsistent with hashCode() contract, use isMimeTypeEqual(String) instead.

Compares only the mimeType against the passed in String and representationClass is not considered in the comparison. If representationClass needs to be compared, then equals(new DataFlavor(s)) may be used.

Parameters
s:String

the mimeType to compare

Returns:boolean

true if the String (MimeType) is equal; false otherwise or if s is null

Annotations
@Deprecated
getDefaultRepresentationClassback to summary
public final Class<?> getDefaultRepresentationClass()

Returns the default representation class.

Returns:Class<?>

the default representation class

getDefaultRepresentationClassAsStringback to summary
public final String getDefaultRepresentationClassAsString()

Returns the name of the default representation class.

Returns:String

the name of the default representation class

getHumanPresentableNameback to summary
public String getHumanPresentableName()

Returns the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries.

Returns:String

the human presentable name for the data format that this DataFlavor represents

getMimeTypeback to summary
public String getMimeType()

Returns the MIME type string for this DataFlavor.

Returns:String

the MIME type string for this flavor

getParameterback to summary
public String getParameter(String paramName)

Returns the human presentable name for this DataFlavor if paramName equals "humanPresentableName". Otherwise returns the MIME type value associated with paramName.

Parameters
paramName:String

the parameter name requested

Returns:String

the value of the name parameter, or null if there is no associated value

getPrimaryTypeback to summary
public String getPrimaryType()

Returns the primary MIME type for this DataFlavor.

Returns:String

the primary MIME type of this DataFlavor

getReaderForTextback 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 java.io.Reader, java.lang.String, java.nio.CharBuffer, [C, java.io.InputStream, java.nio.ByteBuffer, and [B.

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 selectBestTextFlavor for a list of text flavors which do not support the charset parameter.

Parameters
transferable:Transferable

the Transferable whose data will be requested in this flavor

Returns:Reader

a Reader to read the Transferable's data

Exceptions
UnsupportedFlavorException:
if the Transferable does not support this flavor
IOException:
if the data cannot be read because of an I/O error
IllegalArgumentException:
  • if the representation class is not one of the seven listed above
  • if the Transferable has null data
NullPointerException:
if the Transferable is null
UnsupportedEncodingException:
if this flavor's representation is java.io.InputStream, java.nio.ByteBuffer, or [B and this flavor's encoding is not supported by this implementation of the Java platform
Since
1.3
See Also
selectBestTextFlavor
getRepresentationClassback to summary
public Class<?> getRepresentationClass()

Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.

Returns:Class<?>

the Class which objects supporting this DataFlavor will return when this DataFlavor is requested

getSubTypeback to summary
public String getSubType()

Returns the sub MIME type of this DataFlavor.

Returns:String

the Sub MIME type of this DataFlavor

getTextPlainUnicodeFlavorback to summary
public static final DataFlavor getTextPlainUnicodeFlavor()

Returns a DataFlavor representing plain text with Unicode encoding, where:

    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 utf-16le. Oracle's implementation for Solaris and Linux uses the encoding iso-10646-ucs-2.

Returns:DataFlavor

a DataFlavor representing plain text with Unicode encoding

Since
1.3
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns hash code for this DataFlavor. For two equal DataFlavors, hash codes are equal. For the String that matches DataFlavor.equals(String), it is not guaranteed that DataFlavor's hash code is equal to the hash code of the String.

Returns:int

a hash code for this DataFlavor

initHtmlback to summary
private static DataFlavor initHtml(String htmlFlavorType)
initializeback to summary
private void initialize(String mimeType, String humanPresentableName, ClassLoader classLoader) throws MimeTypeParseException, ClassNotFoundException

Common initialization code called from various constructors.

Parameters
mimeType:String

the MIME Content Type (must have a class= param)

humanPresentableName:String

the human Presentable Name or null

classLoader:ClassLoader

the fallback class loader to resolve against

Exceptions
NullPointerException:
if mimeType is null
See Also
tryToLoadClass
isFlavorJavaFileListTypeback to summary
public boolean isFlavorJavaFileListType()

Returns true if the DataFlavor specified represents a list of file objects.

Returns:boolean

true if the DataFlavor specified represents a java.util.List of java.io.File objects

isFlavorRemoteObjectTypeback to summary
public boolean isFlavorRemoteObjectType()

Returns true if the DataFlavor specified represents a remote object.

Returns:boolean

true if the DataFlavor specified represents a Remote Object

isFlavorSerializedObjectTypeback to summary
public boolean isFlavorSerializedObjectType()

Returns true if the DataFlavor specified represents a serialized object.

Returns:boolean

true if the DataFlavor specified represents a Serialized Object

isFlavorTextTypeback to summary
public boolean isFlavorTextType()

Returns whether this DataFlavor is a valid text flavor for this implementation of the Java platform. Only flavors equivalent to DataFlavor.stringFlavor and DataFlavors with a primary MIME type of "text" can be valid text flavors.

If this flavor supports the charset parameter, it must be equivalent to DataFlavor.stringFlavor, or its representation must be java.io.Reader, java.lang.String, java.nio.CharBuffer, [C, java.io.InputStream, java.nio.ByteBuffer, or [B. If the representation is java.io.InputStream, java.nio.ByteBuffer, or [B, then this flavor's charset 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.

If this flavor does not support the charset parameter, its representation must be java.io.InputStream, java.nio.ByteBuffer, or [B.

See selectBestTextFlavor for a list of text flavors which support the charset parameter.

Returns:boolean

true if this DataFlavor is a valid text flavor as described above; false otherwise

Since
1.4
See Also
selectBestTextFlavor
isMimeTypeEqualback 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 DataFlavor. Parameters are not included in the comparison.

Parameters
mimeType:String

the string representation of the MIME type

Returns:boolean

true if the string representation of the MIME type passed in is equivalent to the MIME type of this DataFlavor; false otherwise

Exceptions
NullPointerException:
if mimeType is null
isMimeTypeEqualback to summary
public final boolean isMimeTypeEqual(DataFlavor dataFlavor)

Compares the mimeType of two DataFlavor objects. No parameters are considered.

Parameters
dataFlavor:DataFlavor

the DataFlavor to be compared

Returns:boolean

true if the MimeTypes are equal, otherwise false

isMimeTypeEqualback to summary
private boolean isMimeTypeEqual(MimeType mtype)

Compares the mimeType of two DataFlavor objects. No parameters are considered.

Returns:boolean

true if the MimeTypes are equal, otherwise false

isMimeTypeSerializedObjectback to summary
public boolean isMimeTypeSerializedObject()

Does the DataFlavor represent a serialized object?

Returns:boolean

whether or not a serialized object is represented

isRepresentationClassByteBufferback to summary
public boolean isRepresentationClassByteBuffer()

Returns whether the representation class for this DataFlavor is java.nio.ByteBuffer or a subclass thereof.

Returns:boolean

whether or not the representation class for this DataFlavor is java.nio.ByteBuffer or a subclass thereof

Since
1.4
isRepresentationClassCharBufferback to summary
public boolean isRepresentationClassCharBuffer()

Returns whether the representation class for this DataFlavor is java.nio.CharBuffer or a subclass thereof.

Returns:boolean

whether or not the representation class for this DataFlavor is java.nio.CharBuffer or a subclass thereof

Since
1.4
isRepresentationClassInputStreamback to summary
public boolean isRepresentationClassInputStream()

Does the DataFlavor represent a java.io.InputStream?

Returns:boolean

whether or not this DataFlavor represent a java.io.InputStream

isRepresentationClassReaderback to summary
public boolean isRepresentationClassReader()

Returns whether the representation class for this DataFlavor is java.io.Reader or a subclass thereof.

Returns:boolean

whether or not the representation class for this DataFlavor is java.io.Reader or a subclass thereof

Since
1.4
isRepresentationClassRemoteback to summary
public boolean isRepresentationClassRemote()

Returns true if the representation class is Remote.

Returns:boolean

true if the representation class is Remote

isRepresentationClassSerializableback to summary
public boolean isRepresentationClassSerializable()

Returns true if the representation class can be serialized.

Returns:boolean

true if the representation class can be serialized

isStandardTextRepresentationClassback to summary
private boolean isStandardTextRepresentationClass()

Checks if the representation class is one of the standard text representation classes.

Returns:boolean

true if the representation class is one of the standard text representation classes, otherwise false

matchback to summary
public boolean match(DataFlavor that)

Identical to equals(DataFlavor).

Parameters
that:DataFlavor

the DataFlavor to compare with this

Returns:boolean

true if that is equivalent to this DataFlavor; false otherwise

Since
1.3
See Also
selectBestTextFlavor
normalizeMimeTypeback 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 DataFlavor 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.

Parameters
mimeType:String

the mime type

Returns:String

the mime type

Annotations
@Deprecated
normalizeMimeTypeParameterback to summary
protected String normalizeMimeTypeParameter(String parameterName, String parameterValue)

Deprecated

This method is never invoked by this implementation from 1.1 onwards

Called on DataFlavor for every MIME Type parameter to allow DataFlavor subclasses to handle special parameters like the text/plain charset parameters, whose values are case insensitive. (MIME type parameter values are supposed to be case sensitive.

This method is called for each parameter name/value pair and should return the normalized representation of the parameterValue.

Parameters
parameterName:String

the parameter name

parameterValue:String

the parameter value

Returns:String

the parameter value

Annotations
@Deprecated
paramStringback to summary
private String paramString()
readExternalback to summary
public synchronized void readExternal(ObjectInput is) throws IOException, ClassNotFoundException

Implements java.io.Externalizable.readExternal.

Restores this DataFlavor from a Serialized state.

Exceptions
IOException:

Doc from java.io.Externalizable.readExternal.

if I/O errors occur

ClassNotFoundException:

Doc from java.io.Externalizable.readExternal.

If the class for an object being restored cannot be found.

selectBestTextFlavorback to summary
public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)

Selects the best text DataFlavor from an array of DataFlavors. Only DataFlavor.stringFlavor, and equivalent flavors, and flavors that have a primary MIME type of "text", are considered for selection.

Flavors are first sorted by their MIME types in the following order:

  • "text/sgml"
  • "text/xml"
  • "text/html"
  • "text/rtf"
  • "text/enriched"
  • "text/richtext"
  • "text/uri-list"
  • "text/tab-separated-values"
  • "text/t140"
  • "text/rfc822-headers"
  • "text/parityfec"
  • "text/directory"
  • "text/css"
  • "text/calendar"
  • "application/x-java-serialized-object"
  • "text/plain"
  • "text/<other>"

For example, "text/sgml" will be selected over "text/html", and DataFlavor.stringFlavor will be chosen over DataFlavor.plainTextFlavor.

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:

  • "text/sgml"
  • "text/xml"
  • "text/html"
  • "text/enriched"
  • "text/richtext"
  • "text/uri-list"
  • "text/directory"
  • "text/css"
  • "text/calendar"
  • "application/x-java-serialized-object"
  • "text/plain"
The following MIME types do not support, or are treated as though they do not support, the charset parameter:
  • "text/rtf"
  • "text/tab-separated-values"
  • "text/t140"
  • "text/rfc822-headers"
  • "text/parityfec"
For "text/<other>" MIME types, the first time the JRE needs to determine whether the MIME type supports the charset parameter, it will check whether the parameter is explicitly listed in an arbitrarily chosen 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: java.io.InputStream, java.nio.ByteBuffer, [B, <all others>.

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: java.io.Reader, java.lang.String, java.nio.CharBuffer, [C, <all others>.

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: java.io.InputStream, java.nio.ByteBuffer, [B, <all others>.

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.

Parameters
availableFlavors:DataFlavor[]

an array of available DataFlavors

Returns:DataFlavor

the best (highest fidelity) flavor according to the rules specified above, or null, if availableFlavors is null, has zero length, or contains no text flavors

Since
1.3
setHumanPresentableNameback to summary
public void setHumanPresentableName(String humanPresentableName)

Sets the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries.

Parameters
humanPresentableName:String

the new human presentable name

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

String representation of this DataFlavor and its parameters. The resulting String contains the name of the DataFlavor class, this flavor's MIME type, and its representation class. If this flavor has a primary MIME type of "text", supports the charset parameter, and has an encoded representation, the flavor's charset is also included. See selectBestTextFlavor for a list of text flavors which support the charset parameter.

Returns:String

string representation of this DataFlavor

See Also
selectBestTextFlavor
tryToLoadClassback to summary
protected static final Class<?> tryToLoadClass(String className, ClassLoader fallback) throws ClassNotFoundException

Tries to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified.

Parameters
className:String

the name of the class to be loaded

fallback:ClassLoader

the fallback loader

Returns:Class<?>

the class loaded

Exceptions
ClassNotFoundException:
if class is not found
writeExternalback to summary
public synchronized void writeExternal(ObjectOutput os) throws IOException

Implements java.io.Externalizable.writeExternal.

Serializes this DataFlavor.

Exceptions
IOException:

Doc from java.io.Externalizable.writeExternal.

Includes any I/O exceptions that may occur

Serial data
The mimeType field with the humanPresentableName parameter set, followed by the representationClass field