What is the required DataFlavor to copy files in Mac OSX

霸气de小男生 提交于 2019-12-30 06:49:28

问题


I'm currently working on Java code that can copy files into the system clipboard.

For Windows and Linux I already got it working. For OSX I tried several flavors but the "Paste" action in Finder never cames active.

Any idea which DataFlavor settings are required for Finder?

Used flavors:

DataFlavor.javaFileListFlavor
URILIST_FLAVOR = new DataFlavor( "text/uri-list" );
XFILELIST_FLAVOR = new DataFlavor( "application/x-java-file-list" );
GNOMEFILELIST_FLAVOR = new DataFlavor( "x-special/gnome-copied-files" );

The method to return the data for the flavor:

public Object getTransferData( DataFlavor flavor ) throws UnsupportedFlavorException, IOException {
    if( FILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( DataFlavor.javaFileListFlavor.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return locallist;
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( URILIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    } else if( GNOMEFILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return Arrays.asList( files );
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            // FIXME support cut and copy
            return getStreamData( files, "copy" );
        }
    } else if( XFILELIST_FLAVOR.equals( flavor ) ) {
        if( List.class == flavor.getRepresentationClass() ) {
            return locallist;
        } else if( InputStream.class == flavor.getRepresentationClass() ) {
            return getStreamData( files, null );
        }
    }
    throw new UnsupportedFlavorException( flavor );
}

Thanks, André


回答1:


Maybe you should try DataFlavor#javaFileListFlavor.

Excerpt from the API documentation:

DataFlavor#javaFileListFlavor (Link)

To transfer a list of files to/from Java (and the underlying platform) a DataFlavor of this type/subtype and representation class of java.util.List is used. Each element of the list is required/guaranteed to be of type java.io.File.


来源:https://stackoverflow.com/questions/3228619/what-is-the-required-dataflavor-to-copy-files-in-mac-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!