Class SystemFlavorMap
- java.lang.Object
-
- java.awt.datatransfer.SystemFlavorMap
- All Implemented Interfaces:
-
FlavorMap
,FlavorTable
public final class SystemFlavorMap extends Object implements FlavorMap, FlavorTable
The SystemFlavorMap is a configurable map between "natives" (Strings), which correspond to platform-specific data formats, and "flavors" (DataFlavors), which correspond to platform-independent MIME types. This mapping is used by the data transfer subsystem to transfer data between Java and native applications, and between Java applications in separate VMs.
- Since:
- 1.2
Methods
Modifier and Type | Method | Description |
---|---|---|
void | addFlavorForUnencodedNative(String nat,
DataFlavor flav) | Adds a mapping from a single |
void | addUnencodedNativeForFlavor(DataFlavor flav,
String nat) | Adds a mapping from the specified |
static DataFlavor | decodeDataFlavor(String nat) | Decodes a |
static String | decodeJavaMIMEType(String nat) | Decodes a |
static String | encodeDataFlavor(DataFlavor flav) | Encodes a |
static String | encodeJavaMIMEType(String mimeType) | Encodes a MIME type for use as a |
static FlavorMap | getDefaultFlavorMap() | Returns the default FlavorMap for this thread's ClassLoader. |
List<DataFlavor> | getFlavorsForNative(String nat) | Returns a |
Map<String,DataFlavor> | getFlavorsForNatives(String[] natives) | Returns a |
List<String> | getNativesForFlavor(DataFlavor flav) | Returns a |
Map<DataFlavor,String> | getNativesForFlavors(DataFlavor[] flavors) | Returns a |
static boolean | isJavaMIMEType(String str) | Returns whether the specified |
void | setFlavorsForNative(String nat,
DataFlavor[] flavors) | Discards the current mappings for the specified |
void | setNativesForFlavor(DataFlavor flav,
String[] natives) | Discards the current mappings for the specified |
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods
getDefaultFlavorMap
public static FlavorMap getDefaultFlavorMap()
Returns the default FlavorMap for this thread's ClassLoader.
- Returns:
- the default FlavorMap for this thread's ClassLoader
getNativesForFlavor
public List<String> getNativesForFlavor(DataFlavor flav)
Returns a List
of String
natives to which the specified DataFlavor
can be translated by the data transfer subsystem. The List
will be sorted from best native to worst. That is, the first native will best reflect data in the specified flavor to the underlying native platform.
If the specified DataFlavor
is previously unknown to the data transfer subsystem and the data transfer subsystem is unable to translate this DataFlavor
to any existing native, then invoking this method will establish a mapping in both directions between the specified DataFlavor
and an encoded version of its MIME type as its native.
- Specified by:
-
getNativesForFlavor
in interfaceFlavorTable
- Parameters:
-
flav
- theDataFlavor
whose corresponding natives should be returned. Ifnull
is specified, all natives currently known to the data transfer subsystem are returned in a non-deterministic order. - Returns:
- a
java.util.List
ofjava.lang.String
objects which are platform-specific representations of platform-specific data formats - Since:
- 1.4
- See Also:
encodeDataFlavor(java.awt.datatransfer.DataFlavor)
getFlavorsForNative
public List<DataFlavor> getFlavorsForNative(String nat)
Returns a List
of DataFlavor
s to which the specified String
native can be translated by the data transfer subsystem. The List
will be sorted from best DataFlavor
to worst. That is, the first DataFlavor
will best reflect data in the specified native to a Java application.
If the specified native is previously unknown to the data transfer subsystem, and that native has been properly encoded, then invoking this method will establish a mapping in both directions between the specified native and a DataFlavor
whose MIME type is a decoded version of the native.
If the specified native is not a properly encoded native and the mappings for this native have not been altered with setFlavorsForNative
, then the contents of the List
is platform dependent, but null
cannot be returned.
- Specified by:
-
getFlavorsForNative
in interfaceFlavorTable
- Parameters:
-
nat
- the native whose correspondingDataFlavor
s should be returned. Ifnull
is specified, allDataFlavor
s currently known to the data transfer subsystem are returned in a non-deterministic order. - Returns:
- a
java.util.List
ofDataFlavor
objects into which platform-specific data in the specified, platform-specific native can be translated - Since:
- 1.4
- See Also:
encodeJavaMIMEType(java.lang.String)
getNativesForFlavors
public Map<DataFlavor,String> getNativesForFlavors(DataFlavor[] flavors)
Returns a Map
of the specified DataFlavor
s to their most preferred String
native. Each native value will be the same as the first native in the List returned by getNativesForFlavor
for the specified flavor.
If a specified DataFlavor
is previously unknown to the data transfer subsystem, then invoking this method will establish a mapping in both directions between the specified DataFlavor
and an encoded version of its MIME type as its native.
- Specified by:
-
getNativesForFlavors
in interfaceFlavorMap
- Parameters:
-
flavors
- an array ofDataFlavor
s which will be the key set of the returnedMap
. Ifnull
is specified, a mapping of allDataFlavor
s known to the data transfer subsystem to their most preferredString
natives will be returned. - Returns:
- a
java.util.Map
ofDataFlavor
s toString
natives - See Also:
-
getNativesForFlavor(java.awt.datatransfer.DataFlavor)
,encodeDataFlavor(java.awt.datatransfer.DataFlavor)
getFlavorsForNatives
public Map<String,DataFlavor> getFlavorsForNatives(String[] natives)
Returns a Map
of the specified String
natives to their most preferred DataFlavor
. Each DataFlavor
value will be the same as the first DataFlavor
in the List returned by getFlavorsForNative
for the specified native.
If a specified native is previously unknown to the data transfer subsystem, and that native has been properly encoded, then invoking this method will establish a mapping in both directions between the specified native and a DataFlavor
whose MIME type is a decoded version of the native.
- Specified by:
-
getFlavorsForNatives
in interfaceFlavorMap
- Parameters:
-
natives
- an array ofString
s which will be the key set of the returnedMap
. Ifnull
is specified, a mapping of all supportedString
natives to their most preferredDataFlavor
s will be returned. - Returns:
- a
java.util.Map
ofString
natives toDataFlavor
s - See Also:
-
getFlavorsForNative(java.lang.String)
,encodeJavaMIMEType(java.lang.String)
addUnencodedNativeForFlavor
public void addUnencodedNativeForFlavor(DataFlavor flav, String nat)
Adds a mapping from the specified DataFlavor
(and all DataFlavor
s equal to the specified DataFlavor
) to the specified String
native. Unlike getNativesForFlavor
, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addFlavorForUnencodedNative
as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified or equal DataFlavor
to the specified String
native already exists.
- Parameters:
-
flav
- theDataFlavor
key for the mapping -
nat
- theString
native value for the mapping - Throws:
-
NullPointerException
- if flav or nat isnull
- Since:
- 1.4
- See Also:
addFlavorForUnencodedNative(java.lang.String, java.awt.datatransfer.DataFlavor)
setNativesForFlavor
public void setNativesForFlavor(DataFlavor flav, String[] natives)
Discards the current mappings for the specified DataFlavor
and all DataFlavor
s equal to the specified DataFlavor
, and creates new mappings to the specified String
natives. Unlike getNativesForFlavor
, the mappings will only be established in one direction, and the natives will not be encoded. To establish two-way mappings, call setFlavorsForNative
as well. The first native in the array will represent the highest priority mapping. Subsequent natives will represent mappings of decreasing priority.
If the array contains several elements that reference equal String
natives, this method will establish new mappings for the first of those elements and ignore the rest of them.
It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.
- Parameters:
-
flav
- theDataFlavor
key for the mappings -
natives
- theString
native values for the mappings - Throws:
-
NullPointerException
- if flav or natives isnull
or if natives containsnull
elements - Since:
- 1.4
- See Also:
setFlavorsForNative(java.lang.String, java.awt.datatransfer.DataFlavor[])
addFlavorForUnencodedNative
public void addFlavorForUnencodedNative(String nat, DataFlavor flav)
Adds a mapping from a single String
native to a single DataFlavor
. Unlike getFlavorsForNative
, the mapping will only be established in one direction, and the native will not be encoded. To establish a two-way mapping, call addUnencodedNativeForFlavor
as well. The new mapping will be of lower priority than any existing mapping. This method has no effect if a mapping from the specified String
native to the specified or equal DataFlavor
already exists.
- Parameters:
-
nat
- theString
native key for the mapping -
flav
- theDataFlavor
value for the mapping - Throws:
-
NullPointerException
- ifnat
orflav
isnull
- Since:
- 1.4
- See Also:
addUnencodedNativeForFlavor(java.awt.datatransfer.DataFlavor, java.lang.String)
setFlavorsForNative
public void setFlavorsForNative(String nat, DataFlavor[] flavors)
Discards the current mappings for the specified String
native, and creates new mappings to the specified DataFlavor
s. Unlike getFlavorsForNative
, the mappings will only be established in one direction, and the natives need not be encoded. To establish two-way mappings, call setNativesForFlavor
as well. The first DataFlavor
in the array will represent the highest priority mapping. Subsequent DataFlavor
s will represent mappings of decreasing priority.
If the array contains several elements that reference equal DataFlavor
s, this method will establish new mappings for the first of those elements and ignore the rest of them.
It is recommended that client code not reset mappings established by the data transfer subsystem. This method should only be used for application-level mappings.
- Parameters:
-
nat
- theString
native key for the mappings -
flavors
- theDataFlavor
values for the mappings - Throws:
-
NullPointerException
- ifnat
orflavors
isnull
or ifflavors
containsnull
elements - Since:
- 1.4
- See Also:
setNativesForFlavor(java.awt.datatransfer.DataFlavor, java.lang.String[])
encodeJavaMIMEType
public static String encodeJavaMIMEType(String mimeType)
Encodes a MIME type for use as a String
native. The format of an encoded representation of a MIME type is implementation-dependent. The only restrictions are:
- The encoded representation is
null
if and only if the MIME typeString
isnull
- The encoded representations for two non-
null
MIME typeString
s are equal if and only if theseString
s are equal according toString.equals(Object)
String
prefixed with JAVA_DATAFLAVOR:
. - Parameters:
-
mimeType
- the MIME type to encode - Returns:
- the encoded
String
, ornull
ifmimeType
isnull
encodeDataFlavor
public static String encodeDataFlavor(DataFlavor flav)
Encodes a DataFlavor
for use as a String
native. The format of an encoded DataFlavor
is implementation-dependent. The only restrictions are:
- The encoded representation is
null
if and only if the specifiedDataFlavor
isnull
or its MIME typeString
isnull
- The encoded representations for two non-
null
DataFlavor
s with non-null
MIME typeString
s are equal if and only if the MIME typeString
s of theseDataFlavor
s are equal according toString.equals(Object)
String
of the specified DataFlavor
prefixed with JAVA_DATAFLAVOR:
. - Parameters:
-
flav
- theDataFlavor
to encode - Returns:
- the encoded
String
, ornull
ifflav
isnull
or has anull
MIME type
isJavaMIMEType
public static boolean isJavaMIMEType(String str)
Returns whether the specified String
is an encoded Java MIME type.
- Parameters:
-
str
- theString
to test - Returns:
-
true
if theString
is encoded;false
otherwise
decodeJavaMIMEType
public static String decodeJavaMIMEType(String nat)
Decodes a String
native for use as a Java MIME type.
- Parameters:
-
nat
- theString
to decode - Returns:
- the decoded Java MIME type, or
null
ifnat
is not an encodedString
native
decodeDataFlavor
public static DataFlavor decodeDataFlavor(String nat) throws ClassNotFoundException
Decodes a String
native for use as a DataFlavor
.
- Parameters:
-
nat
- theString
to decode - Returns:
- the decoded
DataFlavor
, ornull
ifnat
is not an encodedString
native - Throws:
-
ClassNotFoundException
- if the class of the data flavor is not loaded
© 1993, 2020, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/11/docs/api/java.datatransfer/java/awt/datatransfer/SystemFlavorMap.html