Each instance represents the opaque concept of a data format as would appear on a clipboard, during drag and drop, or in a file system.

DataFlavor objects are constant and never change once instantiated.

For information on using data transfer with Swing, see How to Use Drag and Drop and Data Transfer, a section in The Java Tutorial, for more information.

@version
1.79, 05/18/04
@author
Blake Sullivan
@author
Laurence P. G. Cable
@author
Jeff Dunn
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
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
representationClassthe class used to transfer data in this flavor
humanPresentableNamethe human-readable string used to identify this flavor; if this parameter is null then the value of the the MIME Content Type is used
Throws
NullPointerExceptionif representationClass is null
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
mimeTypethe string used to identify the MIME type for this flavor; if the the mimeType does not specify a "class=" parameter, or if the class is not successfully loaded, then an IllegalArgumentException is thrown
humanPresentableNamethe human-readable string used to identify this flavor; if this parameter is null then the value of the the MIME Content Type is used
Throws
IllegalArgumentExceptionif mimeType is invalid or if the class is not successfully loaded
NullPointerExceptionif mimeType is null
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
mimeTypethe string used to identify the MIME type for this flavor
humanPresentableNamethe human-readable string used to identify this flavor
classLoaderthe class loader to use
Throws
ClassNotFoundExceptionif the class is not loaded
IllegalArgumentExceptionif mimeType is invalid
NullPointerExceptionif mimeType is null
Constructs a DataFlavor from a mimeType string. The string can specify a "class=" 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
mimeTypethe string used to identify the MIME type for this flavor; if the class specified by "class=" parameter is not successfully loaded, then an ClassNotFoundException is thrown
Throws
ClassNotFoundExceptionif the class is not loaded
IllegalArgumentExceptionif mimeType is invalid
NullPointerExceptionif mimeType is null
The DataFlavor representing a Java Image class, where:
     representationClass = java.awt.Image
     mimeType            = "image/x-java-image"
 
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.
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.

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.
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.
The DataFlavor representing plain text with Unicode encoding, where:
     representationClass = InputStream
     mimeType            = "text/plain; charset=unicode"
 
This DataFlavor has been deprecated because (1) Its representation is an InputStream, an 8-bit based representation, while Unicode is a 16-bit character set; and (2) The charset "unicode" is not well-defined. "unicode" implies a particular platform's implementation of Unicode, not a cross-platform implementation.
@deprecated
as of 1.3. Use DataFlavor.getReaderForText(Transferable) instead of Transferable.getTransferData(DataFlavor.plainTextFlavor).
The DataFlavor representing a Java Unicode String class, where:
     representationClass = java.lang.String
     mimeType           = "application/x-java-serialized-object"        
 
Returns a clone of this DataFlavor.
Return
a clone of this DataFlavor
Tests a DataFlavor to this DataFlavor for equality. 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
thatthe DataFlavor to compare with this
Return
true if that is equivalent to this DataFlavor; false otherwise
Tests an arbitrary Object to this DataFlavor for equality. 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
othe Object to compare with this
Return
true if that is equivalent to this DataFlavor; false otherwise
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.
Return
true if the String (MimeType) is equal
@deprecated
As inconsistent with hashCode() contract, use isMimeTypeEqual(String) instead.
Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class.
Return
The java.lang.Class object that represents the runtime class of the object. The result is of type {@code Class} where X is the erasure of the static type of the expression on which getClass is called.
Returns the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries.
Return
the human presentable name for the data format that this DataFlavor represents
Returns the MIME type string for this DataFlavor.
Return
the MIME type string for this flavor
Returns the human presentable name for this DataFlavor if paramName equals "humanPresentableName". Otherwise returns the MIME type value associated with paramName.
Parameters
paramNamethe parameter name requested
Return
the value of the name parameter, or null if there is no associated value
Returns the primary MIME type for this DataFlavor.
Return
the primary MIME type of this DataFlavor
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
transferablethe Transferable whose data will be requested in this flavor
Return
a Reader to read the Transferable's data
Throws
IllegalArgumentExceptionif the representation class is not one of the seven listed above
IllegalArgumentExceptionif the Transferable has null data
NullPointerExceptionif the Transferable is null
UnsupportedEncodingExceptionif 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
UnsupportedFlavorExceptionif the Transferable does not support this flavor
IOExceptionif the data cannot be read because of an I/O error
@since
1.3
Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.
Return
the Class which objects supporting this DataFlavor will return when this DataFlavor is requested
Returns the sub MIME type of this DataFlavor.
Return
the Sub MIME type of this DataFlavor
Returns a DataFlavor representing plain text with Unicode encoding, where:
     representationClass = java.io.InputStream
     mimeType            = "text/plain;
                            charset=<platform default Unicode encoding>"
 
Sun's implementation for Microsoft Windows uses the encoding utf-16le. Sun's implementation for Solaris and Linux uses the encoding iso-10646-ucs-2.
Return
a DataFlavor representing plain text with Unicode encoding
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.
Return
a hash code for this DataFlavor
Returns true if the DataFlavor specified represents a list of file objects.
Return
true if the DataFlavor specified represents a List of File objects
Returns true if the DataFlavor specified represents a remote object.
Return
true if the DataFlavor specified represents a Remote Object
Returns true if the DataFlavor specified represents a serialized object.
Return
true if the DataFlavor specified represents a Serialized Object
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.

Return
true if this DataFlavor is a valid text flavor as described above; false otherwise
@since
1.4
Compares the mimeType of two DataFlavor objects. No parameters are considered.
Parameters
dataFlavorthe DataFlavor to be compared
Return
true if the MimeTypes are equal, otherwise false
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
mimeTypethe 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 DataFlavor; false otherwise
Throws
NullPointerExceptionif mimeType is null
Does the DataFlavor represent a serialized object?
Returns whether the representation class for this DataFlavor is java.nio.ByteBuffer or a subclass thereof.
@since
1.4
Returns whether the representation class for this DataFlavor is java.nio.CharBuffer or a subclass thereof.
@since
1.4
Does the DataFlavor represent a java.io.InputStream?
Returns whether the representation class for this DataFlavor is java.io.Reader or a subclass thereof.
@since
1.4
Returns true if the representation class is Remote.
Return
true if the representation class is Remote
Returns true if the representation class can be serialized.
Return
true if the representation class can be serialized
Tests a DataFlavor to this DataFlavor for equality. 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
thatthe DataFlavor to compare with this
Return
true if that is equivalent to this DataFlavor; false otherwise
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

  • By executing a synchronized instance method of that object.
  • By executing the body of a synchronized statement that synchronizes on the object.
  • For objects of type Class, by executing a synchronized static method of that class.

Only one thread at a time can own an object's monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Throws
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.
Parameters
inthe stream to read data from in order to restore the object
Throws
IOExceptionif I/O errors occur
ClassNotFoundExceptionIf the class for an object being restored cannot be found.
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
availableFlavorsan array of available DataFlavors
Return
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
Sets the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries.
Parameters
humanPresentableNamethe new human presentable name
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.
Return
string representation of this DataFlavor
Causes current thread to wait until another thread invokes the method or the method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait();
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Throws
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.

The current thread must own this object's monitor.

This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:

  • Some other thread invokes the notify method for this object and thread T happens to be arbitrarily chosen as the thread to be awakened.
  • Some other thread invokes the notifyAll method for this object.
  • Some other thread interrupts thread T.
  • The specified amount of real time has elapsed, more or less. If timeout is zero, however, then real time is not taken into consideration and the thread simply waits until notified.
The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus, on return from the wait method, the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.

A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout);
         ... // Perform action appropriate to condition
     }
 
(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).

If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.

Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.

Parameters
timeoutthe maximum time to wait in milliseconds.
Throws
IllegalArgumentExceptionif the value of timeout is negative.
IllegalMonitorStateExceptionif the current thread is not the owner of the object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

This method is similar to the wait method of one argument, but it allows finer control over the amount of time to wait for a notification before giving up. The amount of real time, measured in nanoseconds, is given by:

 1000000*timeout+nanos

In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:

  • Another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method.
  • The timeout period, specified by timeout milliseconds plus nanos nanoseconds arguments, has elapsed.

The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:

     synchronized (obj) {
         while (<condition does not hold>)
             obj.wait(timeout, nanos);
         ... // Perform action appropriate to condition
     }
 
This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.
Parameters
timeoutthe maximum time to wait in milliseconds.
nanosadditional time, in nanoseconds range 0-999999.
Throws
IllegalArgumentExceptionif the value of timeout is negative or the value of nanos is not in the range 0-999999.
IllegalMonitorStateExceptionif the current thread is not the owner of this object's monitor.
InterruptedExceptionif another thread interrupted the current thread before or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown.
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
Parameters
outthe stream to write the object to
Throws
IOExceptionIncludes any I/O exceptions that may occur
@serialData
Overriding methods should use this tag to describe the data layout of this Externalizable object. List the sequence of element types and, if possible, relate the element to a public/protected field and/or method of this Externalizable class.