Selects the best text
DataFlavor
from an array of
DataFlavor
s. Only
DataFlavor.stringFlavor
, and
equivalent flavors, and flavors that have a primary MIME type of "text",
are considered for selection.
Flavors are first sorted by their MIME types in the following order:
- "text/sgml"
- "text/xml"
- "text/html"
- "text/rtf"
- "text/enriched"
- "text/richtext"
- "text/uri-list"
- "text/tab-separated-values"
- "text/t140"
- "text/rfc822-headers"
- "text/parityfec"
- "text/directory"
- "text/css"
- "text/calendar"
- "application/x-java-serialized-object"
- "text/plain"
- "text/<other>"
For example, "text/sgml" will be selected over
"text/html", and DataFlavor.stringFlavor
will be chosen
over DataFlavor.plainTextFlavor
.
If two or more flavors share the best MIME type in the array, then that
MIME type will be checked to see if it supports the charset parameter.
The following MIME types support, or are treated as though they support,
the charset parameter:
- "text/sgml"
- "text/xml"
- "text/html"
- "text/enriched"
- "text/richtext"
- "text/uri-list"
- "text/directory"
- "text/css"
- "text/calendar"
- "application/x-java-serialized-object"
- "text/plain"
The following MIME types do not support, or are treated as though they
do not support, the charset parameter:
- "text/rtf"
- "text/tab-separated-values"
- "text/t140"
- "text/rfc822-headers"
- "text/parityfec"
For "text/<other>" MIME types, the first time the JRE needs to
determine whether the MIME type supports the charset parameter, it will
check whether the parameter is explicitly listed in an arbitrarily
chosen
DataFlavor
which uses that MIME type. If so, the JRE
will assume from that point on that the MIME type supports the charset
parameter and will not check again. If the parameter is not explicitly
listed, the JRE will assume from that point on that the MIME type does
not support the charset parameter and will not check again. Because
this check is performed on an arbitrarily chosen
DataFlavor
, developers must ensure that all
DataFlavor
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.
Returns:
the best (highest fidelity) flavor according to the rules
specified above, or null
,
if availableFlavors
is null
,
has zero length, or contains no text flavors
Parameters:
- availableFlavors - an array of available DataFlavor
s
Since:
1.3