- java.lang.Object
-
- java.awt.datatransfer.DataFlavor
-
- All Implemented Interfaces:
- Externalizable, Serializable, Cloneable
- Direct Known Subclasses:
- ActivationDataFlavor
public class DataFlavor extends Object implements Externalizable, Cloneable
ADataFlavor
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(java.awt.datatransfer.DataFlavor)
. For example, the MIME type ofimageFlavor
is"image/x-java-image;class=java.awt.Image"
, the primary type isimage
, the subtype isx-java-image
, and the representation class isjava.awt.Image
. WhengetTransferData
is invoked with aDataFlavor
ofimageFlavor
, an instance ofjava.awt.Image
is returned. It's important to note thatDataFlavor
does 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,
DataFlavor
instances 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
DataFlavors
is 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 twoDataFlavors
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
andflavor2
are considered identical. As such, asking aTransferable
for eitherDataFlavor
returns the same results.For more information on the using data transfer with Swing see the How to Use Drag and Drop and Data Transfer, section in Java Tutorial.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static DataFlavor
imageFlavor
TheDataFlavor
representing a Java Image class, where:static DataFlavor
javaFileListFlavor
To transfer a list of files to/from Java (and the underlying platform) aDataFlavor
of this type/subtype and representation class ofjava.util.List
is used.static String
javaJVMLocalObjectMimeType
To transfer a reference to an arbitrary Java object reference that has no associated MIME Content-type, across aTransferable
interface WITHIN THE SAME JVM, aDataFlavor
with this type/subtype is used, with arepresentationClass
equal to the type of the class/interface being passed across theTransferable
.static String
javaRemoteObjectMimeType
In order to pass a live link to a Remote object via a Drag and DropACTION_LINK
operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of theDataFlavor
represents the type of theRemote
interface to be transferred.static String
javaSerializedObjectMimeType
A MIME Content-Type of application/x-java-serialized-object represents a graph of Java object(s) that have been made persistent.static DataFlavor
plainTextFlavor
Deprecated.as of 1.3. UseDataFlavor.getReaderForText(Transferable)
instead ofTransferable.getTransferData(DataFlavor.plainTextFlavor)
.static DataFlavor
stringFlavor
TheDataFlavor
representing a Java Unicode String class, where:
-
Constructor Summary
Constructors Constructor and Description DataFlavor()
Constructs a newDataFlavor
.DataFlavor(Class<?> representationClass, String humanPresentableName)
Constructs aDataFlavor
that represents a Java class.DataFlavor(String mimeType)
Constructs aDataFlavor
from amimeType
string.DataFlavor(String mimeType, String humanPresentableName)
Constructs aDataFlavor
that represents aMimeType
.DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader)
Constructs aDataFlavor
that represents aMimeType
.
-
Method Summary
Methods Modifier and Type Method and Description Object
clone()
Returns a clone of thisDataFlavor
.boolean
equals(DataFlavor that)
This method has the same behavior asequals(Object)
.boolean
equals(Object o)
Indicates whether some other object is "equal to" this one.boolean
equals(String s)
Deprecated.As inconsistent withhashCode()
contract, useisMimeTypeEqual(String)
instead.Class<?>
getDefaultRepresentationClass()
String
getDefaultRepresentationClassAsString()
String
getHumanPresentableName()
Returns the human presentable name for the data format that thisDataFlavor
represents.String
getMimeType()
Returns the MIME type string for thisDataFlavor
.String
getParameter(String paramName)
Returns the human presentable name for thisDataFlavor
ifparamName
equals "humanPresentableName".String
getPrimaryType()
Returns the primary MIME type for thisDataFlavor
.Reader
getReaderForText(Transferable transferable)
Gets a Reader for a text flavor, decoded, if necessary, for the expected charset (encoding).Class<?>
getRepresentationClass()
Returns theClass
which objects supporting thisDataFlavor
will return when thisDataFlavor
is requested.String
getSubType()
Returns the sub MIME type of thisDataFlavor
.static DataFlavor
getTextPlainUnicodeFlavor()
Returns aDataFlavor
representing plain text with Unicode encoding, where:int
hashCode()
Returns hash code for thisDataFlavor
.boolean
isFlavorJavaFileListType()
Returns true if theDataFlavor
specified represents a list of file objects.boolean
isFlavorRemoteObjectType()
Returns true if theDataFlavor
specified represents a remote object.boolean
isFlavorSerializedObjectType()
Returns true if theDataFlavor
specified represents a serialized object.boolean
isFlavorTextType()
Returns whether thisDataFlavor
is a valid text flavor for this implementation of the Java platform.boolean
isMimeTypeEqual(DataFlavor dataFlavor)
Compares themimeType
of twoDataFlavor
objects.boolean
isMimeTypeEqual(String mimeType)
Returns whether the string representation of the MIME type passed in is equivalent to the MIME type of thisDataFlavor
.boolean
isMimeTypeSerializedObject()
Does theDataFlavor
represent a serialized object?boolean
isRepresentationClassByteBuffer()
Returns whether the representation class for thisDataFlavor
isjava.nio.ByteBuffer
or a subclass thereof.boolean
isRepresentationClassCharBuffer()
Returns whether the representation class for thisDataFlavor
isjava.nio.CharBuffer
or a subclass thereof.boolean
isRepresentationClassInputStream()
Does theDataFlavor
represent ajava.io.InputStream
?boolean
isRepresentationClassReader()
Returns whether the representation class for thisDataFlavor
isjava.io.Reader
or a subclass thereof.boolean
isRepresentationClassRemote()
Returns true if the representation class isRemote
.boolean
isRepresentationClassSerializable()
Returns true if the representation class can be serialized.boolean
match(DataFlavor that)
Identical toequals(DataFlavor)
.protected String
normalizeMimeType(String mimeType)
Deprecated.protected String
normalizeMimeTypeParameter(String parameterName, String parameterValue)
Deprecated.void
readExternal(ObjectInput is)
Restores thisDataFlavor
from a Serialized state.static DataFlavor
selectBestTextFlavor(DataFlavor[] availableFlavors)
Selects the best textDataFlavor
from an array ofDataFlavor
s.void
setHumanPresentableName(String humanPresentableName)
Sets the human presentable name for the data format that thisDataFlavor
represents.String
toString()
String representation of thisDataFlavor
and 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.void
writeExternal(ObjectOutput os)
Serializes thisDataFlavor
.
-
-
-
Field Detail
-
stringFlavor
public static final DataFlavor stringFlavor
TheDataFlavor
representing a Java Unicode String class, where:representationClass = java.lang.String mimeType = "application/x-java-serialized-object"
-
imageFlavor
public static final DataFlavor imageFlavor
TheDataFlavor
representing a Java Image class, where:representationClass = java.awt.Image mimeType = "image/x-java-image"
-
plainTextFlavor
@Deprecated public static final DataFlavor plainTextFlavor
Deprecated. as of 1.3. UseDataFlavor.getReaderForText(Transferable)
instead ofTransferable.getTransferData(DataFlavor.plainTextFlavor)
.TheDataFlavor
representing plain text with Unicode encoding, where:representationClass = InputStream mimeType = "text/plain; charset=unicode"
ThisDataFlavor
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.
-
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 thisDataFlavor
identifies 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) aDataFlavor
of this type/subtype and representation class ofjava.util.List
is 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 aTransferable
interface WITHIN THE SAME JVM, aDataFlavor
with this type/subtype is used, with arepresentationClass
equal to the type of the class/interface being passed across theTransferable
.The object reference returned from
Transferable.getTransferData
for aDataFlavor
with 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_LINK
operation a Mime Content Type of application/x-java-remote-object should be used, where the representation class of theDataFlavor
represents the type of theRemote
interface to be transferred.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataFlavor
public DataFlavor()
Constructs a newDataFlavor
. This constructor is provided only for the purpose of supporting theExternalizable
interface. It is not intended for public (client) use.- Since:
- 1.2
-
DataFlavor
public DataFlavor(Class<?> representationClass, String humanPresentableName)
Constructs aDataFlavor
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 flavorhumanPresentableName
- the human-readable string used to identify this flavor; if this parameter isnull
then the value of the the MIME Content Type is used- Throws:
NullPointerException
- ifrepresentationClass
is null
-
DataFlavor
public DataFlavor(String mimeType, String humanPresentableName)
Constructs aDataFlavor
that represents aMimeType
.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 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 the themimeType
does not specify a "class=" parameter, or if the class is not successfully loaded, then anIllegalArgumentException
is thrownhumanPresentableName
- the human-readable string used to identify this flavor; if this parameter isnull
then the value of the the MIME Content Type is used- Throws:
IllegalArgumentException
- ifmimeType
is invalid or if the class is not successfully loadedNullPointerException
- ifmimeType
is null
-
DataFlavor
public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException
Constructs aDataFlavor
that represents aMimeType
.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
- 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
- ifmimeType
is invalidNullPointerException
- ifmimeType
is null
-
DataFlavor
public DataFlavor(String mimeType) throws ClassNotFoundException
Constructs aDataFlavor
from amimeType
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 anClassNotFoundException
is thrown- Throws:
ClassNotFoundException
- if the class is not loadedIllegalArgumentException
- ifmimeType
is invalidNullPointerException
- ifmimeType
is null
-
-
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 thisDataFlavor
and its parameters. The resultingString
contains the name of theDataFlavor
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. SeeselectBestTextFlavor
for a list of text flavors which support the charset parameter.- Overrides:
toString
in classObject
- Returns:
- string representation of this
DataFlavor
- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
getTextPlainUnicodeFlavor
public static final DataFlavor getTextPlainUnicodeFlavor()
Returns aDataFlavor
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 encodingutf-16le
. Sun's implementation for Solaris and Linux uses the encodingiso-10646-ucs-2
.- Returns:
- a
DataFlavor
representing plain text with Unicode encoding - Since:
- 1.3
-
selectBestTextFlavor
public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)
Selects the best textDataFlavor
from an array ofDataFlavor
s. 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.stringFlavor
will 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"
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 chosenDataFlavor
, developers must ensure that allDataFlavor
s 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 availableDataFlavor
s- Returns:
- the best (highest fidelity) flavor according to the rules
specified above, or
null
, ifavailableFlavors
isnull
, 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
selectBestTextFlavor
for a list of text flavors which do not support the charset parameter.- Parameters:
transferable
- theTransferable
whose data will be requested in this flavor- Returns:
- a
Reader
to read theTransferable
's data - Throws:
IllegalArgumentException
- if the representation class is not one of the seven listed aboveIllegalArgumentException
- if theTransferable
hasnull
dataNullPointerException
- if theTransferable
isnull
UnsupportedEncodingException
- if this flavor's representation isjava.io.InputStream
,java.nio.ByteBuffer
, or[B
and this flavor's encoding is not supported by this implementation of the Java platformUnsupportedFlavorException
- if theTransferable
does 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 theClass
which objects supporting thisDataFlavor
will return when thisDataFlavor
is requested.- Returns:
- the
Class
which objects supporting thisDataFlavor
will return when thisDataFlavor
is requested
-
getHumanPresentableName
public String getHumanPresentableName()
Returns the human presentable name for the data format that thisDataFlavor
represents. This name would be localized for different countries.- Returns:
- the human presentable name for the data format that this
DataFlavor
represents
-
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 thisDataFlavor
ifparamName
equals "humanPresentableName". Otherwise returns the MIME type value associated withparamName
.- Parameters:
paramName
- the parameter name requested- Returns:
- the value of the name parameter, or
null
if there is no associated value
-
setHumanPresentableName
public void setHumanPresentableName(String humanPresentableName)
Sets the human presentable name for the data format that thisDataFlavor
represents. This name would be localized for different countries.- Parameters:
humanPresentableName
- the new human presentable name
-
equals
public boolean equals(Object o)
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 returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
The
equals
method for classObject
implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesx
andy
, this method returnstrue
if and only ifx
andy
refer to the same object (x == y
has the valuetrue
).Note that it is generally necessary to override the
hashCode
method whenever this method is overridden, so as to maintain the general contract for thehashCode
method, which states that equal objects must have equal hash codes.The equals comparison for the
DataFlavor
class is implemented as follows: TwoDataFlavor
s 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
, thecharset
parameter must also be equal. If a charset is not explicitly specified for one or bothDataFlavor
s, the platform default encoding is assumed. SeeselectBestTextFlavor
for a list of text flavors which support the charset parameter.- Overrides:
equals
in classObject
- Parameters:
o
- theObject
to compare withthis
- Returns:
true
ifthat
is equivalent to thisDataFlavor
;false
otherwise- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
- It is reflexive: for any non-null reference value
-
equals
public boolean equals(DataFlavor that)
This method has the same behavior asequals(Object)
. The only difference being that it takes aDataFlavor
instance as a parameter.- Parameters:
that
- theDataFlavor
to compare withthis
- Returns:
true
ifthat
is equivalent to thisDataFlavor
;false
otherwise- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
equals
@Deprecated public boolean equals(String s)
Deprecated. As inconsistent withhashCode()
contract, useisMimeTypeEqual(String)
instead.Compares only themimeType
against the passed inString
andrepresentationClass
is not considered in the comparison. IfrepresentationClass
needs to be compared, thenequals(new DataFlavor(s))
may be used.- Parameters:
s
- themimeType
to compare.- Returns:
- true if the String (MimeType) is equal; false otherwise or if
s
isnull
-
hashCode
public int hashCode()
Returns hash code for thisDataFlavor
. For two equalDataFlavor
s, hash codes are equal. For theString
that matchesDataFlavor.equals(String)
, it is not guaranteed thatDataFlavor
's hash code is equal to the hash code of theString
.- Overrides:
hashCode
in classObject
- Returns:
- a hash code for this
DataFlavor
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
-
match
public boolean match(DataFlavor that)
Identical toequals(DataFlavor)
.- Parameters:
that
- theDataFlavor
to compare withthis
- Returns:
true
ifthat
is equivalent to thisDataFlavor
;false
otherwise- 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:
- true if the string representation of the MIME type passed in is
equivalent to the MIME type of this
DataFlavor
; false otherwise - Throws:
NullPointerException
- if mimeType isnull
-
isMimeTypeEqual
public final boolean isMimeTypeEqual(DataFlavor dataFlavor)
Compares themimeType
of twoDataFlavor
objects. No parameters are considered.- Parameters:
dataFlavor
- theDataFlavor
to be compared- Returns:
- true if the
MimeType
s are equal, otherwise false
-
isMimeTypeSerializedObject
public boolean isMimeTypeSerializedObject()
Does theDataFlavor
represent a serialized object?
-
getDefaultRepresentationClass
public final Class<?> getDefaultRepresentationClass()
-
getDefaultRepresentationClassAsString
public final String getDefaultRepresentationClassAsString()
-
isRepresentationClassInputStream
public boolean isRepresentationClassInputStream()
Does theDataFlavor
represent ajava.io.InputStream
?
-
isRepresentationClassReader
public boolean isRepresentationClassReader()
Returns whether the representation class for thisDataFlavor
isjava.io.Reader
or a subclass thereof.- Since:
- 1.4
-
isRepresentationClassCharBuffer
public boolean isRepresentationClassCharBuffer()
Returns whether the representation class for thisDataFlavor
isjava.nio.CharBuffer
or a subclass thereof.- Since:
- 1.4
-
isRepresentationClassByteBuffer
public boolean isRepresentationClassByteBuffer()
Returns whether the representation class for thisDataFlavor
isjava.nio.ByteBuffer
or a subclass thereof.- Since:
- 1.4
-
isRepresentationClassSerializable
public boolean isRepresentationClassSerializable()
Returns true if the representation class can be serialized.- Returns:
- true if the representation class can be serialized
-
isRepresentationClassRemote
public boolean isRepresentationClassRemote()
Returns true if the representation class isRemote
.- Returns:
- true if the representation class is
Remote
-
isFlavorSerializedObjectType
public boolean isFlavorSerializedObjectType()
Returns true if theDataFlavor
specified represents a serialized object.- Returns:
- true if the
DataFlavor
specified represents a Serialized Object
-
isFlavorRemoteObjectType
public boolean isFlavorRemoteObjectType()
Returns true if theDataFlavor
specified represents a remote object.- Returns:
- true if the
DataFlavor
specified represents a Remote Object
-
isFlavorJavaFileListType
public boolean isFlavorJavaFileListType()
Returns true if theDataFlavor
specified represents a list of file objects.- Returns:
- true if the
DataFlavor
specified represents a List of File objects
-
isFlavorTextType
public boolean isFlavorTextType()
Returns whether thisDataFlavor
is a valid text flavor for this implementation of the Java platform. Only flavors equivalent toDataFlavor.stringFlavor
andDataFlavor
s 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'scharset
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:
true
if thisDataFlavor
is a valid text flavor as described above;false
otherwise- Since:
- 1.4
- See Also:
selectBestTextFlavor(java.awt.datatransfer.DataFlavor[])
-
writeExternal
public void writeExternal(ObjectOutput os) throws IOException
Serializes thisDataFlavor
.- Specified by:
writeExternal
in 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 thisDataFlavor
from a Serialized state.- Specified by:
readExternal
in 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:
clone
in classObject
- Returns:
- a clone of this
DataFlavor
- Throws:
CloneNotSupportedException
- if the object's class does not support theCloneable
interface. Subclasses that override theclone
method can also throw this exception to indicate that an instance cannot be cloned.- See Also:
Cloneable
-
normalizeMimeTypeParameter
@Deprecated protected String normalizeMimeTypeParameter(String parameterName, String parameterValue)
Deprecated.Called onDataFlavor
for every MIME Type parameter to allowDataFlavor
subclasses to handle special parameters like the text/plaincharset
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.
-
normalizeMimeType
@Deprecated protected String normalizeMimeType(String mimeType)
Deprecated.Called for each MIME type string to giveDataFlavor
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.
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-java/awt/datatransfer/DataFlavor.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.