java.awt.datatransfer.DataFlavor#isRepresentationClassInputStream ( )源码实例Demo

下面列出了java.awt.datatransfer.DataFlavor#isRepresentationClassInputStream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8-source   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which does not support the
 * 'charset' parameter.
 */
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
    if (!"text".equals(flavor.getPrimaryType()) ||
        doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    return (flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            DataTransferer.byteArrayClass.
                equals(flavor.getRepresentationClass()));
}
 
源代码2 项目: openjdk-8   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which does not support the
 * 'charset' parameter.
 */
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
    if (!"text".equals(flavor.getPrimaryType()) ||
        doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    return (flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            DataTransferer.byteArrayClass.
                equals(flavor.getRepresentationClass()));
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: DataTransferer.java
/**
 * Returns a Set of all DataFlavors for which
 * 1) a mapping from at least one of the specified formats exists in the
 * specified map and
 * 2) the data translation for this mapping can be performed by the data
 * transfer subsystem.
 *
 * @param formats the data formats
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if formats or map is <code>null</code>
 */
public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
    Set flavorSet = new HashSet(formats.length);

    for (int i = 0; i < formats.length; i++) {
        String nat = getNativeForFormat(formats[i]);
        List flavors = map.getFlavorsForNative(nat);

        for (Iterator iter = flavors.iterator(); iter.hasNext(); ) {
            DataFlavor flavor = (DataFlavor)iter.next();

            // Don't explicitly test for String, since it is just a special
            // case of Serializable
            if (flavor.isFlavorTextType() ||
                flavor.isFlavorJavaFileListType() ||
                DataFlavor.imageFlavor.equals(flavor) ||
                flavor.isRepresentationClassSerializable() ||
                flavor.isRepresentationClassInputStream() ||
                flavor.isRepresentationClassRemote())
            {
                flavorSet.add(flavor);
            }
        }
    }

    return flavorSet;
}
 
源代码4 项目: dragonwell8_jdk   文件: DataTransferer.java
/**
 * Returns a Set of all DataFlavors for which
 * 1) a mapping from at least one of the specified formats exists in the
 * specified map and
 * 2) the data translation for this mapping can be performed by the data
 * transfer subsystem.
 *
 * @param formats the data formats
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if formats or map is <code>null</code>
 */
public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
    Set flavorSet = new HashSet(formats.length);

    for (int i = 0; i < formats.length; i++) {
        String nat = getNativeForFormat(formats[i]);
        List flavors = map.getFlavorsForNative(nat);

        for (Iterator iter = flavors.iterator(); iter.hasNext(); ) {
            DataFlavor flavor = (DataFlavor)iter.next();

            // Don't explicitly test for String, since it is just a special
            // case of Serializable
            if (flavor.isFlavorTextType() ||
                flavor.isFlavorJavaFileListType() ||
                DataFlavor.imageFlavor.equals(flavor) ||
                flavor.isRepresentationClassSerializable() ||
                flavor.isRepresentationClassInputStream() ||
                flavor.isRepresentationClassRemote())
            {
                flavorSet.add(flavor);
            }
        }
    }

    return flavorSet;
}
 
源代码5 项目: TencentKona-8   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which supports the
 * 'charset' parameter.
 */
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
    // Although stringFlavor doesn't actually support the charset
    // parameter (because its primary MIME type is not "text"), it should
    // be treated as though it does. stringFlavor is semantically
    // equivalent to "text/plain" data.
    if (DataFlavor.stringFlavor.equals(flavor)) {
        return true;
    }

    if (!"text".equals(flavor.getPrimaryType()) ||
        !doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    Class rep_class = flavor.getRepresentationClass();

    if (flavor.isRepresentationClassReader() ||
        String.class.equals(rep_class) ||
        flavor.isRepresentationClassCharBuffer() ||
        char[].class.equals(rep_class))
    {
        return true;
    }

    if (!(flavor.isRepresentationClassInputStream() ||
          flavor.isRepresentationClassByteBuffer() ||
          byte[].class.equals(rep_class))) {
        return false;
    }

    String charset = flavor.getParameter("charset");

    return (charset != null)
        ? DataTransferer.isEncodingSupported(charset)
        : true; // null equals default encoding which is always supported
}
 
源代码6 项目: hottub   文件: DataTransferer.java
/**
 * Returns a Set of all DataFlavors for which
 * 1) a mapping from at least one of the specified formats exists in the
 * specified map and
 * 2) the data translation for this mapping can be performed by the data
 * transfer subsystem.
 *
 * @param formats the data formats
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if formats or map is <code>null</code>
 */
public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
    Set flavorSet = new HashSet(formats.length);

    for (int i = 0; i < formats.length; i++) {
        String nat = getNativeForFormat(formats[i]);
        List flavors = map.getFlavorsForNative(nat);

        for (Iterator iter = flavors.iterator(); iter.hasNext(); ) {
            DataFlavor flavor = (DataFlavor)iter.next();

            // Don't explicitly test for String, since it is just a special
            // case of Serializable
            if (flavor.isFlavorTextType() ||
                flavor.isFlavorJavaFileListType() ||
                DataFlavor.imageFlavor.equals(flavor) ||
                flavor.isRepresentationClassSerializable() ||
                flavor.isRepresentationClassInputStream() ||
                flavor.isRepresentationClassRemote())
            {
                flavorSet.add(flavor);
            }
        }
    }

    return flavorSet;
}
 
源代码7 项目: jdk8u-jdk   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which does not support the
 * 'charset' parameter.
 */
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
    if (!"text".equals(flavor.getPrimaryType()) ||
        doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    return (flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            byte[].class.equals(flavor.getRepresentationClass()));
}
 
源代码8 项目: openjdk-8-source   文件: DataTransferer.java
/**
 * Returns a Set of all DataFlavors for which
 * 1) a mapping from at least one of the specified formats exists in the
 * specified map and
 * 2) the data translation for this mapping can be performed by the data
 * transfer subsystem.
 *
 * @param formats the data formats
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if formats or map is <code>null</code>
 */
public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
    Set flavorSet = new HashSet(formats.length);

    for (int i = 0; i < formats.length; i++) {
        String nat = getNativeForFormat(formats[i]);
        List flavors = map.getFlavorsForNative(nat);

        for (Iterator iter = flavors.iterator(); iter.hasNext(); ) {
            DataFlavor flavor = (DataFlavor)iter.next();

            // Don't explicitly test for String, since it is just a special
            // case of Serializable
            if (flavor.isFlavorTextType() ||
                flavor.isFlavorJavaFileListType() ||
                DataFlavor.imageFlavor.equals(flavor) ||
                flavor.isRepresentationClassSerializable() ||
                flavor.isRepresentationClassInputStream() ||
                flavor.isRepresentationClassRemote())
            {
                flavorSet.add(flavor);
            }
        }
    }

    return flavorSet;
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which supports the
 * 'charset' parameter.
 */
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
    // Although stringFlavor doesn't actually support the charset
    // parameter (because its primary MIME type is not "text"), it should
    // be treated as though it does. stringFlavor is semantically
    // equivalent to "text/plain" data.
    if (DataFlavor.stringFlavor.equals(flavor)) {
        return true;
    }

    if (!"text".equals(flavor.getPrimaryType()) ||
        !doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    Class rep_class = flavor.getRepresentationClass();

    if (flavor.isRepresentationClassReader() ||
        String.class.equals(rep_class) ||
        flavor.isRepresentationClassCharBuffer() ||
        char[].class.equals(rep_class))
    {
        return true;
    }

    if (!(flavor.isRepresentationClassInputStream() ||
          flavor.isRepresentationClassByteBuffer() ||
          byte[].class.equals(rep_class))) {
        return false;
    }

    String charset = flavor.getParameter("charset");

    return (charset != null)
        ? DataTransferer.isEncodingSupported(charset)
        : true; // null equals default encoding which is always supported
}
 
源代码10 项目: jdk8u-jdk   文件: DataTransferer.java
/**
 * Returns a Set of all DataFlavors for which
 * 1) a mapping from at least one of the specified formats exists in the
 * specified map and
 * 2) the data translation for this mapping can be performed by the data
 * transfer subsystem.
 *
 * @param formats the data formats
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if formats or map is <code>null</code>
 */
public Set getFlavorsForFormatsAsSet(long[] formats, FlavorTable map) {
    Set flavorSet = new HashSet(formats.length);

    for (int i = 0; i < formats.length; i++) {
        String nat = getNativeForFormat(formats[i]);
        List flavors = map.getFlavorsForNative(nat);

        for (Iterator iter = flavors.iterator(); iter.hasNext(); ) {
            DataFlavor flavor = (DataFlavor)iter.next();

            // Don't explicitly test for String, since it is just a special
            // case of Serializable
            if (flavor.isFlavorTextType() ||
                flavor.isFlavorJavaFileListType() ||
                DataFlavor.imageFlavor.equals(flavor) ||
                flavor.isRepresentationClassSerializable() ||
                flavor.isRepresentationClassInputStream() ||
                flavor.isRepresentationClassRemote())
            {
                flavorSet.add(flavor);
            }
        }
    }

    return flavorSet;
}
 
源代码11 项目: jdk8u-jdk   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which supports the
 * 'charset' parameter.
 */
public static boolean isFlavorCharsetTextType(DataFlavor flavor) {
    // Although stringFlavor doesn't actually support the charset
    // parameter (because its primary MIME type is not "text"), it should
    // be treated as though it does. stringFlavor is semantically
    // equivalent to "text/plain" data.
    if (DataFlavor.stringFlavor.equals(flavor)) {
        return true;
    }

    if (!"text".equals(flavor.getPrimaryType()) ||
        !doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    Class rep_class = flavor.getRepresentationClass();

    if (flavor.isRepresentationClassReader() ||
        String.class.equals(rep_class) ||
        flavor.isRepresentationClassCharBuffer() ||
        char[].class.equals(rep_class))
    {
        return true;
    }

    if (!(flavor.isRepresentationClassInputStream() ||
          flavor.isRepresentationClassByteBuffer() ||
          byte[].class.equals(rep_class))) {
        return false;
    }

    String charset = flavor.getParameter("charset");

    return (charset != null)
        ? DataTransferer.isEncodingSupported(charset)
        : true; // null equals default encoding which is always supported
}
 
源代码12 项目: jdk8u-jdk   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which does not support the
 * 'charset' parameter.
 */
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
    if (!"text".equals(flavor.getPrimaryType()) ||
        doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    return (flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            byte[].class.equals(flavor.getRepresentationClass()));
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: DataTransferer.java
/**
 * Returns whether this flavor is a text type which does not support the
 * 'charset' parameter.
 */
public static boolean isFlavorNoncharsetTextType(DataFlavor flavor) {
    if (!"text".equals(flavor.getPrimaryType()) ||
        doesSubtypeSupportCharset(flavor))
    {
        return false;
    }

    return (flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassByteBuffer() ||
            byte[].class.equals(flavor.getRepresentationClass()));
}
 
源代码14 项目: jdk8u_jdk   文件: XDataTransferer.java
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (int i = 0; i < mimeTypes.length; i++) {
                Iterator writers =
                    ImageIO.getImageWritersByMIMEType(mimeTypes[i]);

                while (writers.hasNext()) {
                    ImageWriter imageWriter = (ImageWriter)writers.next();
                    ImageWriterSpi writerSpi =
                        imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                        writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mimeTypes[i]);
                        break;
                    }
                }
            }
        }
    } else if (DataTransferer.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataTransferer.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: DataTransferer.java
/**
 * Returns a Map whose keys are all of the possible formats into which data
 * in the specified DataFlavors can be translated. The value of each key
 * is the DataFlavor in which the Transferable's data should be requested
 * when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 *
 * @param flavors the data flavors
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if flavors or map is <code>null</code>
 */
public SortedMap <Long, DataFlavor> getFormatsForFlavors(
    DataFlavor[] flavors, FlavorTable map)
{
    Map <Long,DataFlavor> formatMap =
        new HashMap <> (flavors.length);
    Map <Long,DataFlavor> textPlainMap =
        new HashMap <> (flavors.length);
    // Maps formats to indices that will be used to sort the formats
    // according to the preference order.
    // Larger index value corresponds to the more preferable format.
    Map indexMap = new HashMap(flavors.length);
    Map textPlainIndexMap = new HashMap(flavors.length);

    int currentIndex = 0;

    // Iterate backwards so that preferred DataFlavors are used over
    // other DataFlavors. (See javadoc for
    // Transferable.getTransferDataFlavors.)
    for (int i = flavors.length - 1; i >= 0; i--) {
        DataFlavor flavor = flavors[i];
        if (flavor == null) continue;

        // Don't explicitly test for String, since it is just a special
        // case of Serializable
        if (flavor.isFlavorTextType() ||
            flavor.isFlavorJavaFileListType() ||
            DataFlavor.imageFlavor.equals(flavor) ||
            flavor.isRepresentationClassSerializable() ||
            flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassRemote())
        {
            List natives = map.getNativesForFlavor(flavor);

            currentIndex += natives.size();

            for (Iterator iter = natives.iterator(); iter.hasNext(); ) {
                Long lFormat =
                    getFormatForNativeAsLong((String)iter.next());
                Integer index = Integer.valueOf(currentIndex--);

                formatMap.put(lFormat, flavor);
                indexMap.put(lFormat, index);

                // SystemFlavorMap.getNativesForFlavor will return
                // text/plain natives for all text/*. While this is good
                // for a single text/* flavor, we would prefer that
                // text/plain native data come from a text/plain flavor.
                if (("text".equals(flavor.getPrimaryType()) &&
                     "plain".equals(flavor.getSubType())) ||
                    flavor.equals(DataFlavor.stringFlavor))
                {
                    textPlainMap.put(lFormat, flavor);
                    textPlainIndexMap.put(lFormat, index);
                }
            }

            currentIndex += natives.size();
        }
    }

    formatMap.putAll(textPlainMap);
    indexMap.putAll(textPlainIndexMap);

    // Sort the map keys according to the formats preference order.
    Comparator comparator =
        new IndexOrderComparator(indexMap, IndexedComparator.SELECT_WORST);
    SortedMap sortedMap = new TreeMap(comparator);
    sortedMap.putAll(formatMap);

    return sortedMap;
}
 
源代码16 项目: TencentKona-8   文件: DataTransferer.java
/**
 * Returns a Map whose keys are all of the possible formats into which data
 * in the specified DataFlavors can be translated. The value of each key
 * is the DataFlavor in which the Transferable's data should be requested
 * when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 *
 * @param flavors the data flavors
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if flavors or map is <code>null</code>
 */
public SortedMap <Long, DataFlavor> getFormatsForFlavors(
    DataFlavor[] flavors, FlavorTable map)
{
    Map <Long,DataFlavor> formatMap =
        new HashMap <> (flavors.length);
    Map <Long,DataFlavor> textPlainMap =
        new HashMap <> (flavors.length);
    // Maps formats to indices that will be used to sort the formats
    // according to the preference order.
    // Larger index value corresponds to the more preferable format.
    Map indexMap = new HashMap(flavors.length);
    Map textPlainIndexMap = new HashMap(flavors.length);

    int currentIndex = 0;

    // Iterate backwards so that preferred DataFlavors are used over
    // other DataFlavors. (See javadoc for
    // Transferable.getTransferDataFlavors.)
    for (int i = flavors.length - 1; i >= 0; i--) {
        DataFlavor flavor = flavors[i];
        if (flavor == null) continue;

        // Don't explicitly test for String, since it is just a special
        // case of Serializable
        if (flavor.isFlavorTextType() ||
            flavor.isFlavorJavaFileListType() ||
            DataFlavor.imageFlavor.equals(flavor) ||
            flavor.isRepresentationClassSerializable() ||
            flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassRemote())
        {
            List natives = map.getNativesForFlavor(flavor);

            currentIndex += natives.size();

            for (Iterator iter = natives.iterator(); iter.hasNext(); ) {
                Long lFormat =
                    getFormatForNativeAsLong((String)iter.next());
                Integer index = Integer.valueOf(currentIndex--);

                formatMap.put(lFormat, flavor);
                indexMap.put(lFormat, index);

                // SystemFlavorMap.getNativesForFlavor will return
                // text/plain natives for all text/*. While this is good
                // for a single text/* flavor, we would prefer that
                // text/plain native data come from a text/plain flavor.
                if (("text".equals(flavor.getPrimaryType()) &&
                     "plain".equals(flavor.getSubType())) ||
                    flavor.equals(DataFlavor.stringFlavor))
                {
                    textPlainMap.put(lFormat, flavor);
                    textPlainIndexMap.put(lFormat, index);
                }
            }

            currentIndex += natives.size();
        }
    }

    formatMap.putAll(textPlainMap);
    indexMap.putAll(textPlainIndexMap);

    // Sort the map keys according to the formats preference order.
    Comparator comparator =
        new IndexOrderComparator(indexMap, IndexedComparator.SELECT_WORST);
    SortedMap sortedMap = new TreeMap(comparator);
    sortedMap.putAll(formatMap);

    return sortedMap;
}
 
源代码17 项目: openjdk-jdk9   文件: XDataTransferer.java
@Override
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataFlavorUtil.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (String mime : mimeTypes) {
                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mime);
                while (writers.hasNext()) {
                    ImageWriter imageWriter = writers.next();
                    ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                            writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mime);
                        break;
                    }
                }
            }
        }
    } else if (DataFlavorUtil.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataFlavorUtil.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
源代码18 项目: TencentKona-8   文件: XDataTransferer.java
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (int i = 0; i < mimeTypes.length; i++) {
                Iterator writers =
                    ImageIO.getImageWritersByMIMEType(mimeTypes[i]);

                while (writers.hasNext()) {
                    ImageWriter imageWriter = (ImageWriter)writers.next();
                    ImageWriterSpi writerSpi =
                        imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                        writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mimeTypes[i]);
                        break;
                    }
                }
            }
        }
    } else if (DataTransferer.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataTransferer.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
源代码19 项目: hottub   文件: XDataTransferer.java
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) {
    LinkedHashSet<String> natives = new LinkedHashSet<>(1);

    if (df == null) {
        return natives;
    }

    String charset = df.getParameter("charset");
    String baseType = df.getPrimaryType() + "/" + df.getSubType();
    String mimeType = baseType;

    if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) {
        mimeType += ";charset=" + charset;
    }

    // Add a mapping to the MIME native whenever the representation class
    // doesn't require translation.
    if (df.getRepresentationClass() != null &&
        (df.isRepresentationClassInputStream() ||
         df.isRepresentationClassByteBuffer() ||
         byte[].class.equals(df.getRepresentationClass()))) {
        natives.add(mimeType);
    }

    if (DataFlavor.imageFlavor.equals(df)) {
        String[] mimeTypes = ImageIO.getWriterMIMETypes();
        if (mimeTypes != null) {
            for (int i = 0; i < mimeTypes.length; i++) {
                Iterator writers =
                    ImageIO.getImageWritersByMIMEType(mimeTypes[i]);

                while (writers.hasNext()) {
                    ImageWriter imageWriter = (ImageWriter)writers.next();
                    ImageWriterSpi writerSpi =
                        imageWriter.getOriginatingProvider();

                    if (writerSpi != null &&
                        writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) {
                        natives.add(mimeTypes[i]);
                        break;
                    }
                }
            }
        }
    } else if (DataTransferer.isFlavorCharsetTextType(df)) {
        // stringFlavor is semantically equivalent to the standard
        // "text/plain" MIME type.
        if (DataFlavor.stringFlavor.equals(df)) {
            baseType = "text/plain";
        }

        for (String encoding : DataTransferer.standardEncodings()) {
            if (!encoding.equals(charset)) {
                natives.add(baseType + ";charset=" + encoding);
            }
        }

        // Add a MIME format without specified charset.
        if (!natives.contains(baseType)) {
            natives.add(baseType);
        }
    }

    return natives;
}
 
源代码20 项目: openjdk-8   文件: DataTransferer.java
/**
 * Returns a Map whose keys are all of the possible formats into which data
 * in the specified DataFlavors can be translated. The value of each key
 * is the DataFlavor in which the Transferable's data should be requested
 * when converting to the format.
 * <p>
 * The map keys are sorted according to the native formats preference
 * order.
 *
 * @param flavors the data flavors
 * @param map the FlavorTable which contains mappings between
 *            DataFlavors and data formats
 * @throws NullPointerException if flavors or map is <code>null</code>
 */
public SortedMap <Long, DataFlavor> getFormatsForFlavors(
    DataFlavor[] flavors, FlavorTable map)
{
    Map <Long,DataFlavor> formatMap =
        new HashMap <> (flavors.length);
    Map <Long,DataFlavor> textPlainMap =
        new HashMap <> (flavors.length);
    // Maps formats to indices that will be used to sort the formats
    // according to the preference order.
    // Larger index value corresponds to the more preferable format.
    Map indexMap = new HashMap(flavors.length);
    Map textPlainIndexMap = new HashMap(flavors.length);

    int currentIndex = 0;

    // Iterate backwards so that preferred DataFlavors are used over
    // other DataFlavors. (See javadoc for
    // Transferable.getTransferDataFlavors.)
    for (int i = flavors.length - 1; i >= 0; i--) {
        DataFlavor flavor = flavors[i];
        if (flavor == null) continue;

        // Don't explicitly test for String, since it is just a special
        // case of Serializable
        if (flavor.isFlavorTextType() ||
            flavor.isFlavorJavaFileListType() ||
            DataFlavor.imageFlavor.equals(flavor) ||
            flavor.isRepresentationClassSerializable() ||
            flavor.isRepresentationClassInputStream() ||
            flavor.isRepresentationClassRemote())
        {
            List natives = map.getNativesForFlavor(flavor);

            currentIndex += natives.size();

            for (Iterator iter = natives.iterator(); iter.hasNext(); ) {
                Long lFormat =
                    getFormatForNativeAsLong((String)iter.next());
                Integer index = Integer.valueOf(currentIndex--);

                formatMap.put(lFormat, flavor);
                indexMap.put(lFormat, index);

                // SystemFlavorMap.getNativesForFlavor will return
                // text/plain natives for all text/*. While this is good
                // for a single text/* flavor, we would prefer that
                // text/plain native data come from a text/plain flavor.
                if (("text".equals(flavor.getPrimaryType()) &&
                     "plain".equals(flavor.getSubType())) ||
                    flavor.equals(DataFlavor.stringFlavor))
                {
                    textPlainMap.put(lFormat, flavor);
                    textPlainIndexMap.put(lFormat, index);
                }
            }

            currentIndex += natives.size();
        }
    }

    formatMap.putAll(textPlainMap);
    indexMap.putAll(textPlainIndexMap);

    // Sort the map keys according to the formats preference order.
    Comparator comparator =
        new IndexOrderComparator(indexMap, IndexedComparator.SELECT_WORST);
    SortedMap sortedMap = new TreeMap(comparator);
    sortedMap.putAll(formatMap);

    return sortedMap;
}