⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataflavor.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * @(#)DataFlavor.java	1.75 04/01/13 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.datatransfer;import java.awt.Toolkit;import java.io.*;import java.nio.*;import java.util.*;import sun.awt.datatransfer.DataTransferer;/** * Each instance represents the opaque concept of a data format as would * appear on a clipboard, during drag and drop, or in a file system. * <p> * <code>DataFlavor</code> objects are constant and never change once * instantiated. * </p> * * @version     1.75, 01/13/04 * @author      Blake Sullivan * @author      Laurence P. G. Cable * @author      Jeff Dunn */public class DataFlavor implements Externalizable, Cloneable {        private static final long serialVersionUID = 8367026044764648243L;    private static final Class ioInputStreamClass = java.io.InputStream.class;    /**     * Tries to load a class from: the bootstrap loader, the system loader,     * the context loader (if one is present) and finally the loader specified.     *     * @param className the name of the class to be loaded     * @param fallback the fallback loader     * @return the class loaded     * @exception ClassNotFoundException if class is not found     */    protected final static Class tryToLoadClass(String className,						ClassLoader fallback)         throws ClassNotFoundException    {	ClassLoader systemClassLoader = (ClassLoader)	    java.security.AccessController.doPrivileged(                new java.security.PrivilegedAction() {		    public Object run() {			ClassLoader cl = Thread.currentThread().			    getContextClassLoader();			return (cl != null)			    ? cl			    : ClassLoader.getSystemClassLoader();		    }		    });		try {	    return Class.forName(className, true, systemClassLoader);	} catch (ClassNotFoundException e2) {	    if (fallback != null) {		return Class.forName(className, true, fallback);	    } else {		throw new ClassNotFoundException(className);	    }	}    }        /*     * private initializer     */        static private DataFlavor createConstant(Class rc, String prn) {        try {            return new DataFlavor(rc, prn);        } catch (Exception e) {            return null;        }    }        /*     * private initializer     */        static private DataFlavor createConstant(String mt, String prn) {        try {            return new DataFlavor(mt, prn);        } catch (Exception e) {            return null;        }    }        /**     * The <code>DataFlavor</code> representing a Java Unicode String class,     * where:     * <pre>     *     representationClass = java.lang.String     *     mimeType           = "application/x-java-serialized-object"             * </pre>      */        public static final DataFlavor stringFlavor = createConstant(java.lang.String.class, "Unicode String");        /**     * The <code>DataFlavor</code> representing a Java Image class,     * where:     * <pre>     *     representationClass = java.awt.Image     *     mimeType            = "image/x-java-image"     * </pre>     */    public static final DataFlavor imageFlavor = createConstant("image/x-java-image; class=java.awt.Image", "Image");        /**     * The <code>DataFlavor</code> representing plain text with Unicode     * encoding, where:     * <pre>     *     representationClass = InputStream     *     mimeType            = "text/plain; charset=unicode"     * </pre>     * This <code>DataFlavor</code> has been <b>deprecated</b> because     * (1) Its representation is an InputStream, an 8-bit based representation,     * while Unicode is a 16-bit character set; and (2) The charset "unicode"     * is not well-defined. "unicode" implies a particular platform's     * implementation of Unicode, not a cross-platform implementation.     *     * @deprecated as of 1.3. Use <code>DataFlavor.getReaderForText(     *             Transferable)</code> instead of <code>Transferable.     *             getTransferData(DataFlavor.plainTextFlavor)</code>.     */        public static final DataFlavor plainTextFlavor = createConstant("text/plain; charset=unicode; class=java.io.InputStream", "Plain Text");             /**     * A MIME Content-Type of application/x-java-serialized-object represents     * a graph of Java object(s) that have been made persistent.     *     * The representation class associated with this <code>DataFlavor</code>     * identifies the Java type of an object returned as a reference     * from an invocation <code>java.awt.datatransfer.getTransferData</code>.     *     */        public static final String javaSerializedObjectMimeType = "application/x-java-serialized-object";        /**     * To transfer a list of files to/from Java (and the underlying     * platform) a <code>DataFlavor</code> of this type/subtype and     * representation class of <code>java.util.List</code> is used.     * Each element of the list is required/guaranteed to be of type     * <code>java.io.File</code>.     */        public static final DataFlavor javaFileListFlavor = createConstant("application/x-java-file-list;class=java.util.List", null);    /**     * To transfer a reference to an arbitrary Java object reference that     * has no associated MIME Content-type, across a <code>Transferable</code>     * interface WITHIN THE SAME JVM, a <code>DataFlavor</code>     * with this type/subtype is used, with a <code>representationClass</code>     * equal to the type of the class/interface being passed across the     * <code>Transferble</code>.     * <p>     * The object reference returned from      * <code>Transferable.getTransferData</code> for a <code>DataFlavor</code>     * with this MIME Content-Type is required to be     * an instance of the representation Class of the <code>DataFlavor</code>.     */     public static final String javaJVMLocalObjectMimeType = "application/x-java-jvm-local-objectref";        /**     * In order to pass a live link to a Remote object via a Drag and Drop     * <code>ACTION_LINK</code> operation a Mime Content Type of     * application/x-java-remote-object should be used,     * where the representation class of the <code>DataFlavor</code>      * represents the type of the <code>Remote</code> interface to be     * transferred.     */    public static final String javaRemoteObjectMimeType = "application/x-java-remote-object";    /**     * Constructs a new <code>DataFlavor</code>.  This constructor is     * provided only for the purpose of supporting the     * <code>Externalizable</code> interface.  It is not      * intended for public (client) use.     *     * @since 1.2     */    public DataFlavor() {         super();     }     /**     * Constructs a fully specified <code>DataFlavor</code>.     *     * @exception NullPointerException if either <code>primaryType</code>,     *            <code>subType</code> or <code>representationClass</code> is null     */    private DataFlavor(String primaryType, String subType, MimeTypeParameterList params, Class representationClass, String humanPresentableName) {        super();        if (primaryType == null) {            throw new NullPointerException("primaryType");        }        if (subType == null) {            throw new NullPointerException("subType");        }        if (representationClass == null) {            throw new NullPointerException("representationClass");        }                if (params == null) params = new MimeTypeParameterList();                params.set("class", representationClass.getName());                if (humanPresentableName == null) {            humanPresentableName = (String)params.get("humanPresentableName");                        if (humanPresentableName == null)                humanPresentableName = primaryType + "/" + subType;        }                try {            mimeType = new MimeType(primaryType, subType, params);        } catch (MimeTypeParseException mtpe) {            throw new IllegalArgumentException("MimeType Parse Exception: " + mtpe.getMessage());        }                this.representationClass  = representationClass;        this.humanPresentableName = humanPresentableName;                mimeType.removeParameter("humanPresentableName");    }        /**     * Constructs a <code>DataFlavor</code> that represents a Java class.     * <p>     * The returned <code>DataFlavor</code> will have the following     * characteristics:     * <pre>     *    representationClass = representationClass     *    mimeType            = application/x-java-serialized-object             * </pre>     * @param representationClass the class used to transfer data in this flavor     * @param humanPresentableName the human-readable string used to identify      *                 this flavor; if this parameter is <code>null</code>     *		       then the value of the the MIME Content Type is used     * @exception NullPointerException if <code>representationClass</code> is null     */    public DataFlavor(Class representationClass, String humanPresentableName) {        this("application", "x-java-serialized-object", null, representationClass, humanPresentableName);        if (representationClass == null) {            throw new NullPointerException("representationClass");        }    }    /**     * Constructs a <code>DataFlavor</code> that represents a     * <code>MimeType</code>.     * <p>     * The returned <code>DataFlavor</code> will have the following     * characteristics:     * <p>     * If the <code>mimeType</code> is     * "application/x-java-serialized-object; class=&lt;representation class&gt;",     * the result is the same as calling     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.     * <p>     * Otherwise:     * <pre>     *     representationClass = InputStream     *     mimeType            = mimeType              * </pre>     * @param mimeType the string used to identify the MIME type for this flavor;     *                 if the the <code>mimeType</code> does not specify a     *                 "class=" parameter, or if the class is not successfully     *                 loaded, then an <code>IllegalArgumentException</code>     *		       is thrown     * @param humanPresentableName the human-readable string used to identify      *                 this flavor; if this parameter is <code>null</code>     *		       then the value of the the MIME Content Type is used     * @exception IllegalArgumentException if <code>mimeType</code> is     *	               invalid or if the class is not successfully loaded     * @exception NullPointerException if <code>mimeType</code> is null     */    public DataFlavor(String mimeType, String humanPresentableName) {        super();        if (mimeType == null) {            throw new NullPointerException("mimeType");        }        try {            initialize(mimeType, humanPresentableName, this.getClass().getClassLoader());        } catch (MimeTypeParseException mtpe) {            throw new IllegalArgumentException("failed to parse:" + mimeType);        } catch (ClassNotFoundException cnfe) {            throw new IllegalArgumentException("can't find specified class: " + cnfe.getMessage());        }    }        /**     * Constructs a <code>DataFlavor</code> that represents a     * <code>MimeType</code>.     * <p>     * The returned <code>DataFlavor</code> will have the following     * characteristics:     * <p>     * If the mimeType is     * "application/x-java-serialized-object; class=&lt;representation class&gt;",     * the result is the same as calling     * <code>new DataFlavor(Class:forName(&lt;representation class&gt;)</code>.     * <p>     * Otherwise:     * <pre>     *     representationClass = InputStream     *     mimeType            = mimeType              * </pre>     * @param mimeType the string used to identify the MIME type for this flavor     * @param humanPresentableName the human-readable string used to      *		identify this flavor     * @param classLoader the class loader to use     * @exception ClassNotFoundException if the class is not loaded     * @exception IllegalArgumentException if <code>mimeType</code> is     *	               invalid     * @exception NullPointerException if <code>mimeType</code> is null     */    public DataFlavor(String mimeType, String humanPresentableName, ClassLoader classLoader) throws ClassNotFoundException {	super();        if (mimeType == null) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -