java.awt.datatransfer
Class DataFlavor

java.lang.Object
  |
  +--java.awt.datatransfer.DataFlavor
All Implemented Interfaces:
Cloneable, Externalizable, Serializable

public class DataFlavor
extends Object
implements Externalizable, Cloneable

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.

See Also:
Serialized Form

Field Summary
static DataFlavor javaFileListFlavor
copy->  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.
static String javaJVMLocalObjectMimeType
copy->  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 Transferble. The object reference returned from Transferable.getTransferData() for a DataFlavor with this MIME Content-Type is required to be an instanceof the representation Class of the DataFlavor.
static String javaRemoteObjectMimeType
copy->  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.
static String javaSerializedObjectMimeType
copy->  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().
static DataFlavor plainTextFlavor
copy->  plainTextFlavor
Deprecated. as of 1.3. Use DataFlavor.getReaderForText( Transferable) 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 (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.

static DataFlavor stringFlavor
copy->  stringFlavor
The DataFlavor representing a Java Unicode String class, where:

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

 
Constructor Summary
DataFlavor
copy->  new DataFlavor()
copy->  <DataFlavor var> = new 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
DataFlavor
copy->  new DataFlavor(, )
copy->  <DataFlavor var> = new DataFlavor(<Class representationClass>, <String humanPresentableName>);
Construct 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 - the class used to transfer data in this flavor
humanPresentableName - the human-readable string used to identify this flavor. If this parameter is null then the value of the the MIME Content Type is used.
DataFlavor
copy->  new DataFlavor( )
copy->  <DataFlavor var> = new DataFlavor(<String mimeType>);
Construct a DataFlavor from a Mime Type 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:
mimeType - the string used to identify the MIME type for this flavor. If the class specified by "class=" parameter is not successfully loaded, then an IllegalArgumentException is thrown.
DataFlavor
copy->  new DataFlavor(, )
copy->  <DataFlavor var> = new DataFlavor(<String mimeType>, <String humanPresentableName>);
Construct 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>) as above

otherwise:

representationClass = InputStream
mimeType = mimeType

Parameters:
mimeType - the 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.
humanPresentableName - the human-readable string used to identify this flavor. If this parameter is null then the value of the the MIME Content Type is used.
DataFlavor
copy->  new DataFlavor(, , )
copy->  <DataFlavor var> = new DataFlavor(<String mimeType>, <String humanPresentableName>, <ClassLoader classLoader>);
Construct 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>) as above

otherwise:

representationClass = InputStream
mimeType = mimeType

Parameters:
mimeType - the string used to identify the MIME type for this flavor
humanPresentableName - the human-readible string used to identify this flavor
 
Method Summary
 Object clone()
copy->  .clone()
copy->  <Object var>=<DataFlavor>.clone();
Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:
 x.clone() != x
will be true, and that the expression:
 x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
 x.clone().equals(x)
will be true, this is not an absolute requirement. Copying an object will typically entail creating a new instance of its class, but it also may require copying of internal data structures as well. No constructors are called.

The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.

The class Object does not itself implement the interface Cloneable, so calling the clone method on an object whose class is Object will result in throwing an exception at run time. The clone method is implemented by the class Object as a convenient, general utility for subclasses that implement the interface Cloneable, possibly also overriding the clone method, in which case the overriding definition can refer to this utility definition by the call:

 super.clone()
Overrides:
clone in class Object
Following copied from class: java.lang.Object
Returns:
a clone of this instance.
Throws:
CloneNotSupportedException - 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.
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable
 boolean equals(DataFlavor that)
copy->  .equals( )
copy->  <boolean var>=<DataFlavor>.equals(<DataFlavor that>);
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 charset parameter must also be equal. If either DataFlavor is of primary type "text", but no charset is specified, the platform default charset is assumed for that DataFlavor.
Returns:
if the DataFlavors represent exactly the same type.
 boolean equals(Object o)
copy->  .equals( )
copy->  <boolean var>=<DataFlavor>.equals(<Object o>);
If the object is an instance of DataFlavor, representationClass and MIME type will be compared. This method does not use equals(String) method, so it does not return true for the objects of String type.
Overrides:
equals in class Object
Returns:
if the objects are equal
 boolean equals(String s)
copy->  .equals( )
copy->  <boolean var>=<DataFlavor>.equals(<String s>);
Deprecated. As inconsistent with hashCode() contract, use isMimeTypeEqual(String) instead.

Compare 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.
Returns:
if the String (MimeType) is equal
 Class getDefaultRepresentationClass()
copy->  .getDefaultRepresentationClass()
copy->  <Class var>=<DataFlavor>.getDefaultRepresentationClass();
 String getDefaultRepresentationClassAsString()
copy->  .getDefaultRepresentationClassAsString()
copy->  <String var>=<DataFlavor>.getDefaultRepresentationClassAsString();
 String getHumanPresentableName()
copy->  .getHumanPresentableName()
copy->  <String var>=<DataFlavor>.getHumanPresentableName();
Returns the human presentable name for the data foramt that this DataFlavor represents. This name would be localized for different countries
 String getMimeType()
copy->  .getMimeType()
copy->  <String var>=<DataFlavor>.getMimeType();
Returns the MIME type string for this DataFlavor
 String getParameter(String paramName)
copy->  .getParameter( )
copy->  <String var>=<DataFlavor>.getParameter(<String paramName>);
Returns:
the value of the name parameter
 String getPrimaryType()
copy->  .getPrimaryType()
copy->  <String var>=<DataFlavor>.getPrimaryType();
Returns:
the primary MIME type of this DataFlavor
 Reader getReaderForText(Transferable transferable)
copy->  .getReaderForText( )
copy->  <Reader var>=<DataFlavor>.getReaderForText(<Transferable transferable>);
Gets a reader for an input stream, decoded for the expected charset (encoding). This works only if the representation class of this flavor is java.io.InputStream (or a subclass). In case of representation class being Reader the result will be this class itself.
Returns:
a Reader to read the data
Throws:
IllegalArgumentException - if the representation class is not java.io.InputStream or java.lang.String
IllegalArgumentException - if the charset (character encoding) is not supported by the JDK.
IllegalArgumentException - if the transferable has null data.
NullPointerException - if the transferable argument is null.
UnsupportedEncodingException - if the encoding is not supported by this flavor.
UnsupportedFlavorException - if the transferable does not support this flavor.
IOException - if the data cannot be read because of an I/O error.
 Class getRepresentationClass()
copy->  .getRepresentationClass()
copy->  <Class var>=<DataFlavor>.getRepresentationClass();
Returns the Class which objects supporting this DataFlavor will return when this DataFlavor is requested.
 String getSubType()
copy->  .getSubType()
copy->  <String var>=<DataFlavor>.getSubType();
Returns:
the Sub MIME type of this DataFlavor
static DataFlavor getTextPlainUnicodeFlavor()
copy->  DataFlavor.getTextPlainUnicodeFlavor()
copy->  <DataFlavor var>=DataFlavor.getTextPlainUnicodeFlavor();
 int hashCode()
copy->  .hashCode()
copy->  <int var>=<DataFlavor>.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.
Overrides:
hashCode in class Object
Returns:
a hash code for this DataFlavor
 boolean isFlavorJavaFileListType()
copy->  .isFlavorJavaFileListType()
copy->  <boolean var>=<DataFlavor>.isFlavorJavaFileListType();
Returns:
if flavor specified represents a List of File objects
 boolean isFlavorRemoteObjectType()
copy->  .isFlavorRemoteObjectType()
copy->  <boolean var>=<DataFlavor>.isFlavorRemoteObjectType();
Returns:
if the DataFlavor specified represents a Remote Object
 boolean isFlavorSerializedObjectType()
copy->  .isFlavorSerializedObjectType()
copy->  <boolean var>=<DataFlavor>.isFlavorSerializedObjectType();
Returns:
if the DataFlavor specified represents a Serialized Object
 boolean isMimeTypeEqual(DataFlavor dataFlavor)
copy->  .isMimeTypeEqual( )
copy->  <boolean var>=<DataFlavor>.isMimeTypeEqual(<DataFlavor dataFlavor>);
Compare the mimeType of two DataFlavor objects no parameters are considered
Returns:
if the MimeTypes are equal
 boolean isMimeTypeEqual(String mimeType)
copy->  .isMimeTypeEqual( )
copy->  <boolean var>=<DataFlavor>.isMimeTypeEqual(<String mimeType>);
Is the string representation of the MIME type passed in equivalent to the MIME type of this DataFlavor? Parameters are not incuded in the comparison. This may involve adding default attributes for some MIME types (like adding charset=US-ASCII to text/plain MIME types that have no charset parameter specified) When null is passed as a parameter, the result is false.
Returns:
if the string representation of the MIME type passed is equivalent to the MIME type of this DataFlavor.
 boolean isMimeTypeSerializedObject()
copy->  .isMimeTypeSerializedObject()
copy->  <boolean var>=<DataFlavor>.isMimeTypeSerializedObject();
does the DataFlavor represent a serialized object?
 boolean isRepresentationClassInputStream()
copy->  .isRepresentationClassInputStream()
copy->  <boolean var>=<DataFlavor>.isRepresentationClassInputStream();
does the DataFlavor represent a java.io.InputStream
 boolean isRepresentationClassRemote()
copy->  .isRepresentationClassRemote()
copy->  <boolean var>=<DataFlavor>.isRepresentationClassRemote();
Returns:
true if the representation class is Remote
 boolean isRepresentationClassSerializable()
copy->  .isRepresentationClassSerializable()
copy->  <boolean var>=<DataFlavor>.isRepresentationClassSerializable();
Returns:
true if the representation class can be serialized
 boolean match(DataFlavor that)
copy->  .match( )
copy->  <boolean var>=<DataFlavor>.match(<DataFlavor that>);
Two DataFlavors match if their primary types, subtypes, and representation classes are all equal. Additionally, if the primary type is "text", the charset parameter is also considered. If either DataFlavor is of primary type "text", but no charset is specified, the platform default charset is assumed for that DataFlavor.
protected  String normalizeMimeType(String mimeType)
copy->  .normalizeMimeType( )
copy->  <String var>=<DataFlavor>.normalizeMimeType(<String mimeType>);
Deprecated.  

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 This method is never invoked by this implementation from 1.1 onwards
protected  String normalizeMimeTypeParameter(String parameterName, String parameterValue)
copy->  .normalizeMimeTypeParameter(, )
copy->  <String var>=<DataFlavor>.normalizeMimeTypeParameter(<String parameterName>, <String parameterValue>);
Deprecated.  

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 This method is never invoked by this implementation from 1.1 onwards

 void readExternal(ObjectInput is)
copy->  .readExternal( )
copy->  <DataFlavor>.readExternal(<ObjectInput is>);
restore this DataFlavor from an Serialized state
Specified by:
readExternal in interface Externalizable
Following copied from interface: java.io.Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
IOException - if I/O errors occur
ClassNotFoundException - If the class for an object being restored cannot be found.
static DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)
copy->  DataFlavor.selectBestTextFlavor( )
copy->  <DataFlavor var>=DataFlavor.selectBestTextFlavor(<DataFlavor[] availableFlavors>);
Returns:
the best (highest fidelity) flavor in an encoding supported by the JDK, or null if none can be found.
 void setHumanPresentableName(String humanPresentableName)
copy->  .setHumanPresentableName( )
copy->  <DataFlavor>.setHumanPresentableName(<String humanPresentableName>);
Sets the human presentable name for the data format that this DataFlavor represents. This name would be localized for different countries
 String toString()
copy->  .toString()
copy->  <String var>=<DataFlavor>.toString();
String representation of this DataFlavor and its parameters. The result String contains name of DataFlavor class, representation class and Mime type of this Flavor.
Overrides:
toString in class Object
Returns:
string representation of this DataFlavor
protected static Class tryToLoadClass(String className, ClassLoader fallback)
copy->  DataFlavor.tryToLoadClass(, )
copy->  <Class var>=DataFlavor.tryToLoadClass(<String className>, <ClassLoader fallback>);
tried to load a class from: the bootstrap loader, the system loader, the context loader (if one is present) and finally the loader specified
Parameters:
fallback - the fallback loader
Throws:
ClassNotFoundException -  
 void writeExternal(ObjectOutput os)
copy->  .writeExternal( )
copy->  <DataFlavor>.writeExternal(<ObjectOutput os>);
Serialize this DataFlavor
Specified by:
writeExternal in interface Externalizable
Following copied from interface: java.io.Externalizable
Parameters:
out - the stream to write the object to
Throws:
IOException - Includes any I/O exceptions that may occur
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait