public class DataFlavor extends Object implements Externalizable, Cloneable
Modifier and Type | Field and Description |
---|---|
static DataFlavor |
imageFlavor
This is an image flavor used for transferring images.
|
static DataFlavor |
javaFileListFlavor
This is a data flavor used for transferring lists of files.
|
static String |
javaJVMLocalObjectMimeType
This is the MIME type used to transfer a Java object reference within
the same JVM.
|
static String |
javaRemoteObjectMimeType
This is the MIME type used to transfer a link to a remote object.
|
static String |
javaSerializedObjectMimeType
This is the MIME type used for transferring a serialized object.
|
static DataFlavor |
plainTextFlavor
Deprecated.
The charset unicode is platform specific and InputStream
deals with bytes not chars. Use
getRederForText() . |
static DataFlavor |
stringFlavor
This is the data flavor used for transferring Java strings.
|
Constructor and Description |
---|
DataFlavor()
Empty public constructor needed for externalization.
|
DataFlavor(Class<?> representationClass,
String humanPresentableName)
Initializes a new instance of
DataFlavor . |
DataFlavor(String mimeType)
Initializes a new instance of
DataFlavor with the specified
MIME type. |
DataFlavor(String mimeType,
String humanPresentableName)
Initializes a new instance of
DataFlavor with the
specified MIME type and description. |
DataFlavor(String mimeType,
String humanPresentableName,
ClassLoader classLoader)
Initializes a new instance of
DataFlavor with the
specified MIME type and description. |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a copy of this object.
|
boolean |
equals(DataFlavor flavor)
This method test the specified
DataFlavor for equality
against this object. |
boolean |
equals(Object obj)
This method test the specified
Object for equality
against this object. |
boolean |
equals(String str)
Deprecated.
Not compatible with
hashCode() .
Use isMimeTypeEqual() |
Class<?> |
getDefaultRepresentationClass()
XXX - Currently returns
java.io.InputStream . |
String |
getDefaultRepresentationClassAsString()
XXX - Currently returns
java.io.InputStream . |
String |
getHumanPresentableName()
Returns the human presentable name for this flavor.
|
String |
getMimeType()
Returns the MIME type of this flavor.
|
String |
getParameter(String paramName)
Returns the value of the named MIME type parameter, or
null
if the parameter does not exist. |
String |
getPrimaryType()
Returns the primary MIME type for this flavor.
|
Reader |
getReaderForText(Transferable transferable)
Creates a
Reader for a given Transferable . |
Class<?> |
getRepresentationClass()
Returns the representation class for this flavor.
|
String |
getSubType()
Returns the MIME subtype for this flavor.
|
static DataFlavor |
getTextPlainUnicodeFlavor()
XXX - Currently returns
plainTextFlavor . |
int |
hashCode()
Returns the hash code for this data flavor.
|
boolean |
isFlavorJavaFileListType()
Tests whether or not this flavor represents a list of files.
|
boolean |
isFlavorRemoteObjectType()
Tests whether or not this flavor represents a remote object.
|
boolean |
isFlavorSerializedObjectType()
Tests whether or not this flavor represents a serialized object.
|
boolean |
isFlavorTextType()
Returns whether this
DataFlavor is a valid text flavor for
this implementation of the Java platform. |
boolean |
isMimeTypeEqual(DataFlavor flavor)
Tests the MIME type of this object for equality against the specified
data flavor's MIME type
|
boolean |
isMimeTypeEqual(String mimeType)
Tests the MIME type of this object for equality against the specified
MIME type.
|
boolean |
isMimeTypeSerializedObject()
Tests whether or not this flavor represents a serialized object.
|
boolean |
isRepresentationClassByteBuffer()
Returns whether the representation class for this DataFlavor is
|
boolean |
isRepresentationClassCharBuffer()
Returns whether the representation class for this DataFlavor is
|
boolean |
isRepresentationClassInputStream()
Tests whether or not this flavor has a representation class of
java.io.InputStream . |
boolean |
isRepresentationClassReader()
Returns whether the representation class for this DataFlavor is
|
boolean |
isRepresentationClassRemote()
Tests whether the representation class for his flavor is remote.
|
boolean |
isRepresentationClassSerializable()
Tests whether the representation class for this flavor is
serializable.
|
boolean |
match(DataFlavor dataFlavor)
Returns
true when the given DataFlavor
matches this one. |
protected String |
normalizeMimeType(String type)
Deprecated.
|
protected String |
normalizeMimeTypeParameter(String name,
String value)
Deprecated.
|
void |
readExternal(ObjectInput stream)
De-serialize this class.
|
static DataFlavor |
selectBestTextFlavor(DataFlavor[] availableFlavors)
Selects the best supported text flavor on this implementation.
|
void |
setHumanPresentableName(String humanPresentableName)
Sets the human presentable name to the specified value.
|
String |
toString()
Returns a string representation of this DataFlavor.
|
protected static Class<?> |
tryToLoadClass(String className,
ClassLoader classLoader)
This method attempts to load the named class.
|
void |
writeExternal(ObjectOutput stream)
Serialize this class.
|
public static final DataFlavor plainTextFlavor
getRederForText()
.java.io.InputStream
.public static final DataFlavor stringFlavor
java.lang.String
.public static final DataFlavor javaFileListFlavor
java.util.List
, with each
element of the list being a java.io.File
.public static final DataFlavor imageFlavor
java.awt.Image
.public static final String javaSerializedObjectMimeType
public static final String javaJVMLocalObjectMimeType
public static final String javaRemoteObjectMimeType
public DataFlavor()
public DataFlavor(Class<?> representationClass, String humanPresentableName)
DataFlavor
. The class
and human readable name are specified, the MIME type will be
"application/x-java-serialized-object". If the human readable name
is not specified (null
) then the human readable name
will be the same as the MIME type.representationClass
- The representation class for this object.humanPresentableName
- The display name of the object.public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException
DataFlavor
with the
specified MIME type and description. If the MIME type has a
"class=<rep class>" parameter then the representation class will
be the class name specified. Otherwise the class defaults to
java.io.InputStream
. If the human readable name
is not specified (null
) then the human readable name
will be the same as the MIME type.mimeType
- The MIME type for this flavor.humanPresentableName
- The display name of this flavor.classLoader
- The class loader for finding classes if the default
class loaders do not work.IllegalArgumentException
- If the representation class
specified cannot be loaded.ClassNotFoundException
- If the class is not loaded.public DataFlavor(String mimeType, String humanPresentableName)
DataFlavor
with the
specified MIME type and description. If the MIME type has a
"class=<rep class>" parameter then the representation class will
be the class name specified. Otherwise the class defaults to
java.io.InputStream
. If the human readable name
is not specified (null
) then the human readable name
will be the same as the MIME type. This is the same as calling
new DataFlavor(mimeType, humanPresentableName, null)
.mimeType
- The MIME type for this flavor.humanPresentableName
- The display name of this flavor.IllegalArgumentException
- If the representation class
specified cannot be loaded.public DataFlavor(String mimeType) throws ClassNotFoundException
DataFlavor
with the specified
MIME type. This type can have a "class=" parameter to specify the
representation class, and then the class must exist or an exception will
be thrown. If there is no "class=" parameter then the representation class
will be java.io.InputStream
. This is the same as calling
new DataFlavor(mimeType, null)
.mimeType
- The MIME type for this flavor.IllegalArgumentException
- If a class is not specified in
the MIME type.ClassNotFoundException
- If the class cannot be loaded.protected static final Class<?> tryToLoadClass(String className, ClassLoader classLoader) throws ClassNotFoundException
className
- The name of the class to load.classLoader
- The class loader to use if all others fail, which
may be null
.ClassNotFoundException
- If the class cannot be loaded.public static final DataFlavor getTextPlainUnicodeFlavor()
plainTextFlavor
.public static final DataFlavor selectBestTextFlavor(DataFlavor[] availableFlavors)
null
when none of the given flavors is liked.
The DataFlavor
returned the first data flavor in the
array that has either a representation class which is (a subclass of)
Reader
or String
, or has a representation
class which is (a subclass of) InputStream
and has a
primary MIME type of "text" and has an supported encoding.public String getMimeType()
public Class<?> getRepresentationClass()
public String getHumanPresentableName()
public String getPrimaryType()
public String getSubType()
public String getParameter(String paramName)
null
if the parameter does not exist.paramName
- The name of the paramter.public void setHumanPresentableName(String humanPresentableName)
humanPresentableName
- The new display name.public boolean isMimeTypeEqual(String mimeType)
mimeType
- The MIME type to test against.true
if the MIME type is equal to this object's
MIME type (ignoring parameters), false
otherwise.NullPointerException
- If mimeType is null.public final boolean isMimeTypeEqual(DataFlavor flavor)
flavor
- The flavor to test against.true
if the flavor's MIME type is equal to this
object's MIME type, false
otherwise.public boolean isMimeTypeSerializedObject()
true
if this flavor represents a serialized
object, false
otherwise.public boolean isRepresentationClassInputStream()
java.io.InputStream
.true
if the representation class of this flavor
is java.io.InputStream
, false
otherwise.public boolean isRepresentationClassSerializable()
true
if the representation class is serializable,
false
otherwise.public boolean isRepresentationClassRemote()
true
if the representation class is remote,
false
otherwise.public boolean isFlavorSerializedObjectType()
true
if this flavor represents a serialized
object, false
otherwise.public boolean isFlavorRemoteObjectType()
true
if this flavor represents a remote object,
false
otherwise.public boolean isFlavorJavaFileListType()
true
if this flavor represents a list of files,
false
otherwise.public Object clone() throws CloneNotSupportedException
clone
in class Object
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.Cloneable
public boolean equals(DataFlavor flavor)
DataFlavor
for equality
against this object. This will be true if the MIME type and
representation class are the equal. If the primary type is 'text'
then also the value of the charset parameter is compared. In such a
case when the charset parameter isn't given then the charset is
assumed to be equal to the default charset of the platform. All
other parameters are ignored.flavor
- The DataFlavor
to test against.true
if the flavor is equal to this object,
false
otherwise.public boolean equals(Object obj)
Object
for equality
against this object. This will be true if the following conditions
are met:
null
.DataFlavor
.equals
in class Object
obj
- The Object
to test against.true
if the flavor is equal to this object,
false
otherwise.Object.hashCode()
public boolean equals(String str)
hashCode()
.
Use isMimeTypeEqual()
str
- The string to test against.true
if the string is equal to this object's MIME
type, false
otherwise.public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean match(DataFlavor dataFlavor)
true
when the given DataFlavor
matches this one.protected String normalizeMimeTypeParameter(String name, String value)
name
- The parameter name.value
- The parameter value.protected String normalizeMimeType(String type)
type
- The MIME type.public void writeExternal(ObjectOutput stream) throws IOException
writeExternal
in interface Externalizable
stream
- The ObjectOutput
stream to serialize to.IOException
- If an error occurs.public void readExternal(ObjectInput stream) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
stream
- The ObjectInput
stream to deserialize from.IOException
- If an error ocurs.ClassNotFoundException
- If the class for an object being restored
cannot be found.public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public final Class<?> getDefaultRepresentationClass()
java.io.InputStream
.public final String getDefaultRepresentationClassAsString()
java.io.InputStream
.public Reader getReaderForText(Transferable transferable) throws UnsupportedFlavorException, IOException
Reader
for a given Transferable
.
If the representation class is a (subclass of) Reader
then an instance of the representation class is returned. If the
representatation class is a String
then a
StringReader
is returned. And if the representation class
is a (subclass of) InputStream
and the primary MIME type
is "text" then a InputStreamReader
for the correct charset
encoding is returned.transferable
- The Transferable
for which a text
Reader
is requested.IllegalArgumentException
- If the representation class is not one
of the seven listed above or the Transferable has null data.NullPointerException
- If the Transferable is null.UnsupportedFlavorException
- when the transferable doesn't
support this DataFlavor
. Or if the representable class
isn't a (subclass of) Reader
, String
,
InputStream
and/or the primary MIME type isn't "text".IOException
- when any IOException occurs.UnsupportedEncodingException
- if the "charset" isn't supported
on this platform.public boolean isRepresentationClassByteBuffer()
or a subclass thereof.
public boolean isRepresentationClassCharBuffer()
or a subclass thereof.
public boolean isRepresentationClassReader()
or a subclass thereof.
public boolean isFlavorTextType()
DataFlavor
is a valid text flavor for
this implementation of the Java platform. Only flavors equivalent to
DataFlavor.stringFlavor
and DataFlavor
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 be
java.io.Reader
, java.lang.String
,
java.nio.CharBuffer
, java.io.InputStream
or
java.nio.ByteBuffer
,
If the representation is java.io.InputStream
or
java.nio.ByteBuffer
, 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
.
See selectBestTextFlavor
for a list of text flavors which
support the charset parameter.
true
if this DataFlavor
is a valid
text flavor as described above; false
otherwiseselectBestTextFlavor(java.awt.datatransfer.DataFlavor[])