Data Transfer Architecture

Before we consider any more advanced data transfer examples, it is important that you understand the Java 1.1 java.awt.datatransfer infrastructure that the javax.swing.TransferHandler mechanism relies upon. The java.awt.datatransfer.DataFlavor class is perhaps the most central class; it represents the type of data to be transferred. Every data flavor consists of a human-readable name, a Class object that specifies the Java data type of the transferred data, and a MIME type that specifies the encoding used during data transfer. The DataFlavor class predefines a couple of commonly used flavors for transferring strings and lists of File objects. It also predefines several MIME types used with those flavors. For example, DataFlavor.stringFlavor can transfer Java String objects as Unicode text. It has a representation class of java.lang.String and a MIME type of:

application/x-java-serialized-object; class=java.lang.String

The java.awt.datatransfer.Transferable interface is another important piece of the data transfer picture. This interface specifies three methods that should be implemented by any object that wants to make data available for transfer: getTransferDataFlavors( ), which returns an array of all the DataFlavor types it can use to transfer its data; isDataFlavorSupported( ), which checks whether the Transferable object supports a given flavor; and the most important method, getTransferData( ), which actually returns the data in a format ...

Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.