Abstract Interface Transferable in Java Quick Guide in 2021

Share and Enjoy !

Abstract Interface Transferable in Java

The transferable interface defines the methods that a class must define if it is to act as the source object in a data transfer operation. getTransferDataFlavors() should return an array of DataFlavor objects that specify the data types or formats in which the object can provide its data.

The DataFlavor objects should be ordered from the best format (most richly descriptive) to the worst format. isDataFlavorSupported() must return a boolean value indicating whether it can transfer data using a specified DataFlavor.

Finally, getTransferData() must return an object that represents the data formatted as required by the specified DataFlavor. StringSelection is a pre-defined class that implements the Transferable interface for the transfer of string data.

In short, the Transferable interface is implemented by objects that can be placed on Clipboards.

The structure of interface Transferable is given as

public abstract interface Transferable {
// Public Instance Methods
public abstract Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException;
public abstract DataFlavor[] getTransferDataFlavors();
public abstract boolean isDataFlavorSupported(DataFlavor flavor);

The details of the class structure are given as follows:

public abstract Object getTransferData (DataFlavor flavor);

public abstract Object getTransferData (DataFlavor flavor) method returns the data this Transferable object represents. The class of objects returned depends on the flavor requested.

Further visit: Final Modifier in Java – 6 Important Points To Know

This method returns the data represented by this Transferable object, in the requested flavor

flavor – The requested flavor for the returned data.

public abstract DataFlavor[] getTransferDataFlavors();

public abstract DataFlavor[] getTransferDataFlavors() method returns the data flavors, sorted from most to least descriptive.

READ  Empty Statements in Java

This method returns an array of supported data flavors.

public abstract boolean isDataFlavorSupported (DataFlavor flavor);

public abstract boolean isDataFlavorSupported (DataFlavor flavor) method returns true if flavor is supported; false otherwise.

This method returns true if the flavor is supported; false otherwise.

flavor – The flavor in question.

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *