- java.lang.Object
-
- java.awt.datatransfer.DataFlavor
-
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable
public class DataFlavor extends Object implements Externalizable, Cloneable
ADataFlavorprovides meta information about data.DataFlavoris typically used to access data on the clipboard, or during a drag and drop operation.An instance of
DataFlavorencapsulates 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(java.awt.datatransfer.DataFlavor). For example, the MIME type ofimageFlavoris"image/x-java-image;class=java.awt.Image", the primary type isimage, the subtype isx-java-image, and the representation class isjava.awt.Image. WhengetTransferDatais invoked with aDataFlavorofimageFlavor, an instance ofjava.awt.Imageis returned. It's important to note thatDataFlavordoes no error checking against the representation class. It is up to consumers ofDataFlavor, such asTransferable, to honor the representation class.
Note, if you do not specify a representation class when creating aDataFlavor, the default representation class is used. See appropriate documentation forDataFlavor's constructors.Also,
DataFlavorinstances with the "text" primary MIME type may have a "charset" parameter. Refer to RFC 2046 andselectBestTextFlavor(java.awt.datatransfer.DataFlavor[])for details on "text" MIME types and the "charset" parameter.Equality of
DataFlavorsis determined by the primary type, subtype, and representation class. Refer toequals(DataFlavor)for details. When determining equality, any optional parameters are ignored. For example, the following produces twoDataFlavorsthat 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,flavor1andflavor2are considered identical. As such, asking aTransferablefor eitherDataFlavorreturns 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.
- Since:
- 1.1
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DataFlavorallHtmlFlavorRepresents a piece of an HTML markup.static DataFlavorfragmentHtmlFlavorRepresents a piece of an HTML markup.static DataFlavorimageFlavorTheDataFlavorrepresenting a Java Image class, where:static DataFlavorjavaFileListFlavorTo transfer a list of files to/from Java (and the underlying platform) aDataFlavorof this type/subtype and representation class ofjava.util.Listis used.static StringjavaJVMLocalObjectMimeTypeTo transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across aTransferableinterface WITHIN THE SAME JVM, aDataFlavorwith this type/subtype is used, with arepresentationClassequal to the type of the class/interface being passed across theTransferable.static StringjavaRemoteObjectMimeTypeIn order to pass a live link to a Remote object via a Drag and DropACTION_LINKoperation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of theDataFlavorrepresents the type of theRemoteinterface to be transferred.static StringjavaSerializedObjectMimeTypeA MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent.static DataFlavorplainTextFlavorDeprecated.as of 1.3.static DataFlavorselectionHtmlFlavorRepresents a piece of an HTML markup.static DataFlavorstringFlavorTheDataFlavorrepresenting a Java Unicode String class, where:
-
Constructor Summary
Constructors Constructor Description DataFlavor()Constructs a newDataFlavor.DataFlavor(Class<?> representationClass, String humanPresentableName)Constructs aDataFlavorthat represents a Java class.DataFlavor(String mimeType)Constructs aDataFlavorfrom amimeTypestring.DataFlavor(String mimeType, String humanPresentableName)Constructs aDataFlavorthat represents aMimeType.DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader)Constructs aDataFlavorthat represents aMimeType.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Objectclone()Returns a clone of thisDataFlavor.booleanequals(DataFlavor that)This method has the same behavior asequals(Object).booleanequals(Object o)Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.booleanequals(String s)Deprecated.As inconsistent withhashCode()contract, useisMimeTypeEqual(String)instead.Class<?>getDefaultRepresentationClass()Returns the default representation class.StringgetDefaultRepresentationClassAsString()Returns the name of the default representation class.StringgetHumanPresentableName()Returns the human presentable name for the data format that thisDataFlavorrepresents.StringgetMimeType()Returns the MIME type string for thisDataFlavor.StringgetParameter(String paramName)Returns the human presentable name for thisDataFlavorifparamNameequals "humanPresentableName".StringgetPrimaryType()Returns the primary MIME type for thisDataFlavor.ReadergetReaderForText(Transferable transferable)Gets a Reader for a text flavor, decoded, if necessary, for the expected charset (encoding).Class<?>getRepresentationClass()Returns theClasswhich objects supporting thisDataFlavorwill return when thisDataFlavoris requested.StringgetSubType()Returns the sub MIME type of thisDataFlavor.static DataFlavorgetTextPlainUnicodeFlavor()Returns aDataFlavorrepresenting plain text with Unicode encoding, where:inthashCode()Returns hash code for thisDataFlavor.booleanisFlavorJavaFileListType()Returnstrueif theDataFlavorspecified represents a list of file objects.booleanisFlavorRemoteObjectType()Returnstrueif theDataFlavorspecified represents a remote object.booleanisFlavorSerializedObjectType()Returnstrueif theDataFlavorspecified represents a serialized object.booleanisFlavorTextType()Returns whether thisDataFlavoris a valid text flavor for this implementation of the Java platform.booleanisMimeTypeEqual(DataFlavor dataFlavor)Compares themimeTypeof twoDataFlavorobjects.booleanisMimeTypeEqual(String mimeType)Returns whether the string representation of the MIME type passed in is equivalent to the MIME type of thisDataFlavor.booleanisMimeTypeSerializedObject()Does theDataFlavorrepresent a serialized object?booleanisRepresentationClassByteBuffer()Returns whether the representation class for thisDataFlavorisjava.nio.ByteBufferor a subclass thereof.booleanisRepresentationClassCharBuffer()Returns whether the representation class for thisDataFlavorisjava.nio.CharBufferor a subclass thereof.booleanisRepresentationClassInputStream()Does theDataFlavorrepresent ajava.io.InputStream?booleanisRepresentationClassReader()Returns whether the representation class for thisDataFlavorisjava.io.Readeror a subclass thereof.booleanisRepresentationClassRemote()Returnstrueif the representation class isRemote.booleanisRepresentationClassSerializable()Returnstrueif the representation class can be serialized.booleanmatch(DataFlavor that)Identical toequals(DataFlavor).protected StringnormalizeMimeType(String mimeType)Deprecated.This method is never invoked by this implementation from 1.1 onwardsprotected StringnormalizeMimeTypeParameter(String parameterName, String parameterValue)Deprecated.This method is never invoked by this implementation from 1.1 onwardsvoidreadExternal(ObjectInput is)Restores thisDataFlavorfrom a Serialized state.static DataFlavorselectBestTextFlavor(DataFlavor[] availableFlavors)Selects the best textDataFlavorfrom an array ofDataFlavors.voidsetHumanPresentableName(String humanPresentableName)Sets the human presentable name for the data format that thisDataFlavorrepresents.StringtoString()String representation of thisDataFlavorand its parameters.protected static Class<?>tryToLoadClass(String className, ClassLoader 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.voidwriteExternal(ObjectOutput os)Serializes thisDataFlavor.
-
-
-
Field Detail
-
stringFlavor
public static final DataFlavor stringFlavor
TheDataFlavorrepresenting a Java Unicode String class, where:representationClass = java.lang.String mimeType = "application/x-java-serialized-object"
-
imageFlavor
public static final DataFlavor imageFlavor
TheDataFlavorrepresenting a Java Image class, where:representationClass = java.awt.Image mimeType = "image/x-java-image"Will benullifjava.awt.Imageis not visible, thejava.desktopmodule is not loaded, or thejava.desktopmodule is not in the run-time image.
-
plainTextFlavor
@Deprecated public static final DataFlavor plainTextFlavor
Deprecated.as of 1.3. UsegetReaderForText(java.awt.datatransfer.Transferable)instead ofTransferable.getTransferData(DataFlavor.plainTextFlavor).TheDataFlavorrepresenting plain text with Unicode encoding, where:representationClass = InputStream mimeType = "text/plain; charset=unicode"ThisDataFlavorhas 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
-
javaSerializedObjectMimeType
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
DataFlavoridentifies the Java type of an object returned as a reference from an invocationjava.awt.datatransfer.getTransferData.- See Also:
- Constant Field Values
-
javaFileListFlavor
public static final DataFlavor javaFileListFlavor
To transfer a list of files to/from Java (and the underlying platform) aDataFlavorof this type/subtype and representation class ofjava.util.Listis used. Each element of the list is required/guaranteed to be of typejava.io.File.
-
javaJVMLocalObjectMimeType
public static final String javaJVMLocalObjectMimeType
To transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across aTransferableinterface WITHIN THE SAME JVM, aDataFlavorwith this type/subtype is used, with arepresentationClassequal to the type of the class/interface being passed across theTransferable.The object reference returned from
Transferable.getTransferDatafor aDataFlavorwith this MIME Content-Type is required to be an instance of the representation Class of theDataFlavor.- See Also:
- Constant Field Values
-
javaRemoteObjectMimeType
public static final String javaRemoteObjectMimeType
In order to pass a live link to a Remote object via a Drag and DropACTION_LINKoperation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of theDataFlavorrepresents the type of theRemoteinterface to be transferred.- See Also:
- Constant Field Values
-
selectionHtmlFlavor
public static 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 aTransferableinstance, 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
-
fragmentHtmlFlavor
public static 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 aTransferableinstance, no additional changes will be made.representationClass = String mimeType = "text/html"- Since:
- 1.8
-
allHtmlFlavor
public static 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 aTransferableinstance, no additional changes will be made.representationClass = String mimeType = "text/html"- Since:
- 1.8
-
-
Constructor Detail
-
DataFlavor
public DataFlavor()
Constructs a newDataFlavor. This constructor is provided only for the purpose of supporting theExternalizableinterface. It is not intended for public (client) use.- Since:
- 1.2
-
DataFlavor
public DataFlavor(Class<?> representationClass, String humanPresentableName)
Constructs aDataFlavorthat represents a Java class.The returned
DataFlavorwill have the following characteristics:representationClass = representationClass mimeType = application/x-java-serialized-object- Parameters:
representationClass- the class used to transfer data in this flavorhumanPresentableName- the human-readable string used to identify this flavor; if this parameter isnullthen the value of the MIME Content Type is used- Throws:
NullPointerException- ifrepresentationClassisnull
-
DataFlavor
public DataFlavor(String mimeType, String humanPresentableName)
Constructs aDataFlavorthat represents aMimeType.The returned
DataFlavorwill have the following characteristics:If the
mimeTypeis "application/x-java-serialized-object; class=<representation class>", the result is the same as callingnew DataFlavor(Class.forName(<representation class>).Otherwise:
representationClass = InputStream mimeType = mimeType- Parameters:
mimeType- the string used to identify the MIME type for this flavor; if themimeTypedoes not specify a "class=" parameter, or if the class is not successfully loaded, then anIllegalArgumentExceptionis thrownhumanPresentableName- the human-readable string used to identify this flavor; if this parameter isnullthen the value of the MIME Content Type is used- Throws:
IllegalArgumentException- ifmimeTypeis invalid or if the class is not successfully loadedNullPointerException- ifmimeTypeisnull
-
DataFlavor
public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException
Constructs aDataFlavorthat represents aMimeType.The returned
DataFlavorwill 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- the string used to identify the MIME type for this flavorhumanPresentableName- the human-readable string used to identify this flavorclassLoader- the class loader to use- Throws:
ClassNotFoundException- if the class is not loadedIllegalArgumentException- ifmimeTypeis invalidNullPointerException- ifmimeTypeisnull
-
DataFlavor
public DataFlavor(String mimeType) throws ClassNotFoundException
Constructs aDataFlavorfrom amimeTypestring. The string can specify a "class=<fully specified Java class name>" parameter to create aDataFlavorwith the desired representation class. If the string does not contain "class=" parameter,java.io.InputStreamis 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 aClassNotFoundExceptionis thrown- Throws:
ClassNotFoundException- if the class is not loadedIllegalArgumentException- ifmimeTypeis invalidNullPointerException- ifmimeTypeisnull
-
-
Method Detail
-
tryToLoadClass
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- the name of the class to be loadedfallback- the fallback loader- Returns:
- the class loaded
- Throws:
ClassNotFoundException- if class is not found
-
toString
public String toString()
String representation of thisDataFlavorand its parameters. The resultingStringcontains the name of theDataFlavorclass, 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. SeeselectBestTextFlavorfor a list of text flavors which support the charset parameter.- Overrides:
toStringin classObject- Returns:
- string representation of this
DataFlavor - See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
getTextPlainUnicodeFlavor
public static final DataFlavor getTextPlainUnicodeFlavor()
Returns aDataFlavorrepresenting 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 encodingiso-10646-ucs-2. - Returns:
- a
DataFlavorrepresenting plain text with Unicode encoding - Since:
- 1.3
-
selectBestTextFlavor
public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)
Selects the best textDataFlavorfrom an array ofDataFlavors. OnlyDataFlavor.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.stringFlavorwill be chosen overDataFlavor.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"
- "text/rtf"
- "text/tab-separated-values"
- "text/t140"
- "text/rfc822-headers"
- "text/parityfec"
DataFlavorwhich 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 chosenDataFlavor, developers must ensure that allDataFlavors 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- an array of availableDataFlavors- Returns:
- the best (highest fidelity) flavor according to the rules
specified above, or
null, ifavailableFlavorsisnull, has zero length, or contains no text flavors - Since:
- 1.3
-
getReaderForText
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 arejava.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
selectBestTextFlavorfor a list of text flavors which do not support the charset parameter.- Parameters:
transferable- theTransferablewhose data will be requested in this flavor- Returns:
- a
Readerto read theTransferable's data - Throws:
IllegalArgumentException- if the representation class is not one of the seven listed aboveIllegalArgumentException- if theTransferablehasnulldataNullPointerException- if theTransferableisnullUnsupportedEncodingException- if this flavor's representation isjava.io.InputStream,java.nio.ByteBuffer, or[Band this flavor's encoding is not supported by this implementation of the Java platformUnsupportedFlavorException- if theTransferabledoes not support this flavorIOException- if the data cannot be read because of an I/O error- Since:
- 1.3
- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
getMimeType
public String getMimeType()
Returns the MIME type string for thisDataFlavor.- Returns:
- the MIME type string for this flavor
-
getRepresentationClass
public Class<?> getRepresentationClass()
Returns theClasswhich objects supporting thisDataFlavorwill return when thisDataFlavoris requested.- Returns:
- the
Classwhich objects supporting thisDataFlavorwill return when thisDataFlavoris requested
-
getHumanPresentableName
public String getHumanPresentableName()
Returns the human presentable name for the data format that thisDataFlavorrepresents. This name would be localized for different countries.- Returns:
- the human presentable name for the data format that this
DataFlavorrepresents
-
getPrimaryType
public String getPrimaryType()
Returns the primary MIME type for thisDataFlavor.- Returns:
- the primary MIME type of this
DataFlavor
-
getSubType
public String getSubType()
Returns the sub MIME type of thisDataFlavor.- Returns:
- the Sub MIME type of this
DataFlavor
-
getParameter
public String getParameter(String paramName)
Returns the human presentable name for thisDataFlavorifparamNameequals "humanPresentableName". Otherwise returns the MIME type value associated withparamName.- Parameters:
paramName- the parameter name requested- Returns:
- the value of the name parameter, or
nullif there is no associated value
-
setHumanPresentableName
public void setHumanPresentableName(String humanPresentableName)
Sets the human presentable name for the data format that thisDataFlavorrepresents. This name would be localized for different countries.- Parameters:
humanPresentableName- the new human presentable name
-
equals
public boolean equals(Object o)
Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. The implementation in Object answers true only if the argument is the exact same object as the receiver (==).The equals comparison for the
DataFlavorclass is implemented as follows: TwoDataFlavors 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 notjava.io.Reader,java.lang.String,java.nio.CharBuffer, or[C, thecharsetparameter must also be equal. If a charset is not explicitly specified for one or bothDataFlavors, the platform default encoding is assumed. SeeselectBestTextFlavorfor a list of text flavors which support the charset parameter.- Overrides:
equalsin classObject- Parameters:
o- theObjectto compare withthis- Returns:
trueifthatis equivalent to thisDataFlavor;falseotherwise- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
equals
public boolean equals(DataFlavor that)
This method has the same behavior asequals(Object). The only difference being that it takes aDataFlavorinstance as a parameter.- Parameters:
that- theDataFlavorto compare withthis- Returns:
trueifthatis equivalent to thisDataFlavor;falseotherwise- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
equals
@Deprecated public boolean equals(String s)
Deprecated.As inconsistent withhashCode()contract, useisMimeTypeEqual(String)instead.Compares only themimeTypeagainst the passed inStringandrepresentationClassis not considered in the comparison. IfrepresentationClassneeds to be compared, thenequals(new DataFlavor(s))may be used.- Parameters:
s- themimeTypeto compare- Returns:
trueif the String (MimeType) is equal;falseotherwise or ifsisnull
-
hashCode
public int hashCode()
Returns hash code for thisDataFlavor. For two equalDataFlavors, hash codes are equal. For theStringthat matchesDataFlavor.equals(String), it is not guaranteed thatDataFlavor's hash code is equal to the hash code of theString.- Overrides:
hashCodein classObject- Returns:
- a hash code for this
DataFlavor - See Also:
Object.equals(java.lang.Object)
-
match
public boolean match(DataFlavor that)
Identical toequals(DataFlavor).- Parameters:
that- theDataFlavorto compare withthis- Returns:
trueifthatis equivalent to thisDataFlavor;falseotherwise- Since:
- 1.3
- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
isMimeTypeEqual
public boolean isMimeTypeEqual(String mimeType)
Returns whether the string representation of the MIME type passed in is equivalent to the MIME type of thisDataFlavor. Parameters are not included in the comparison.- Parameters:
mimeType- the string representation of the MIME type- Returns:
trueif the string representation of the MIME type passed in is equivalent to the MIME type of thisDataFlavor;falseotherwise- Throws:
NullPointerException- if mimeType isnull
-
isMimeTypeEqual
public final boolean isMimeTypeEqual(DataFlavor dataFlavor)
Compares themimeTypeof twoDataFlavorobjects. No parameters are considered.- Parameters:
dataFlavor- theDataFlavorto be compared- Returns:
trueif theMimeTypes are equal, otherwisefalse
-
isMimeTypeSerializedObject
public boolean isMimeTypeSerializedObject()
Does theDataFlavorrepresent a serialized object?- Returns:
- whether or not a serialized object is represented
-
getDefaultRepresentationClass
public final Class<?> getDefaultRepresentationClass()
Returns the default representation class.- Returns:
- the default representation class
-
getDefaultRepresentationClassAsString
public final String getDefaultRepresentationClassAsString()
Returns the name of the default representation class.- Returns:
- the name of the default representation class
-
isRepresentationClassInputStream
public boolean isRepresentationClassInputStream()
Does theDataFlavorrepresent ajava.io.InputStream?- Returns:
- whether or not this
DataFlavorrepresent ajava.io.InputStream
-
isRepresentationClassReader
public boolean isRepresentationClassReader()
Returns whether the representation class for thisDataFlavorisjava.io.Readeror a subclass thereof.- Returns:
- whether or not the representation class for this
DataFlavorisjava.io.Readeror a subclass thereof - Since:
- 1.4
-
isRepresentationClassCharBuffer
public boolean isRepresentationClassCharBuffer()
Returns whether the representation class for thisDataFlavorisjava.nio.CharBufferor a subclass thereof.- Returns:
- whether or not the representation class for this
DataFlavorisjava.nio.CharBufferor a subclass thereof - Since:
- 1.4
-
isRepresentationClassByteBuffer
public boolean isRepresentationClassByteBuffer()
Returns whether the representation class for thisDataFlavorisjava.nio.ByteBufferor a subclass thereof.- Returns:
- whether or not the representation class for this
DataFlavorisjava.nio.ByteBufferor a subclass thereof - Since:
- 1.4
-
isRepresentationClassSerializable
public boolean isRepresentationClassSerializable()
Returnstrueif the representation class can be serialized.- Returns:
trueif the representation class can be serialized
-
isRepresentationClassRemote
public boolean isRepresentationClassRemote()
Returnstrueif the representation class isRemote.- Returns:
trueif the representation class isRemote
-
isFlavorSerializedObjectType
public boolean isFlavorSerializedObjectType()
Returnstrueif theDataFlavorspecified represents a serialized object.- Returns:
trueif theDataFlavorspecified represents a Serialized Object
-
isFlavorRemoteObjectType
public boolean isFlavorRemoteObjectType()
Returnstrueif theDataFlavorspecified represents a remote object.- Returns:
trueif theDataFlavorspecified represents a Remote Object
-
isFlavorJavaFileListType
public boolean isFlavorJavaFileListType()
Returnstrueif theDataFlavorspecified represents a list of file objects.- Returns:
trueif theDataFlavorspecified represents ajava.util.Listofjava.io.Fileobjects
-
isFlavorTextType
public boolean isFlavorTextType()
Returns whether thisDataFlavoris a valid text flavor for this implementation of the Java platform. Only flavors equivalent toDataFlavor.stringFlavorandDataFlavors 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 bejava.io.Reader,java.lang.String,java.nio.CharBuffer,[C,java.io.InputStream,java.nio.ByteBuffer, or[B. If the representation isjava.io.InputStream,java.nio.ByteBuffer, or[B, then this flavor'scharsetparameter 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
selectBestTextFlavorfor a list of text flavors which support the charset parameter.- Returns:
trueif thisDataFlavoris a valid text flavor as described above;falseotherwise- Since:
- 1.4
- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
writeExternal
public void writeExternal(ObjectOutput os) throws IOException
Serializes thisDataFlavor.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
os- the stream to write the object to- Throws:
IOException- Includes any I/O exceptions that may occur
-
readExternal
public void readExternal(ObjectInput is) throws IOException, ClassNotFoundException
Restores thisDataFlavorfrom a Serialized state.- Specified by:
readExternalin interfaceExternalizable- Parameters:
is- the stream to read data from in order to restore the object- Throws:
IOException- if I/O errors occurClassNotFoundException- If the class for an object being restored cannot be found.
-
clone
public Object clone() throws CloneNotSupportedException
Returns a clone of thisDataFlavor.- Overrides:
clonein classObject- Returns:
- a clone of this
DataFlavor - Throws:
CloneNotSupportedException- if the receiver's class does not implement the interface Cloneable.
-
normalizeMimeTypeParameter
@Deprecated protected String normalizeMimeTypeParameter(String parameterName, String parameterValue)
Deprecated.This method is never invoked by this implementation from 1.1 onwardsCalled onDataFlavorfor every MIME Type parameter to allowDataFlavorsubclasses to handle special parameters like the text/plaincharsetparameters, 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- the parameter nameparameterValue- the parameter value- Returns:
- the parameter value
-
normalizeMimeType
@Deprecated protected String normalizeMimeType(String mimeType)
Deprecated.This method is never invoked by this implementation from 1.1 onwardsCalled for each MIME type string to giveDataFlavorsubtypes 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- the mime type- Returns:
- the mime type
-
-