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

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

源代码1 项目: dragonwell8_jdk   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码2 项目: TencentKona-8   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码3 项目: TencentKona-8   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码4 项目: jdk8u-jdk   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码5 项目: hottub   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码6 项目: jdk8u60   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码7 项目: openjdk-jdk8u   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码9 项目: hottub   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码10 项目: jdk8u-dev-jdk   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码12 项目: jdk8u-dev-jdk   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码13 项目: openjdk-8   文件: XDataTransferer.java
protected byte[] imageToPlatformBytes(Image image, long format)
  throws IOException {
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation to " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码14 项目: openjdk-jdk9   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
@Override
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码15 项目: jdk8u_jdk   文件: XDataTransferer.java
/**
 * Translates either a byte array or an input stream which contain
 * platform-specific image data in the given format into an Image.
 */
protected Image platformImageBytesToImage(
    byte[] bytes, long format) throws IOException
{
    String mimeType = null;
    if (format == PNG_ATOM.getAtom()) {
        mimeType = "image/png";
    } else if (format == JFIF_ATOM.getAtom()) {
        mimeType = "image/jpeg";
    } else {
        // Check if an image MIME format.
        try {
            String nat = getNativeForFormat(format);
            DataFlavor df = new DataFlavor(nat);
            String primaryType = df.getPrimaryType();
            if ("image".equals(primaryType)) {
                mimeType = df.getPrimaryType() + "/" + df.getSubType();
            }
        } catch (Exception e) {
            // Not an image MIME format.
        }
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    } else {
        String nativeFormat = getNativeForFormat(format);
        throw new IOException("Translation from " + nativeFormat +
                              " is not supported.");
    }
}
 
源代码16 项目: 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;
}
 
源代码17 项目: dragonwell8_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;
}
 
源代码18 项目: jdk8u60   文件: 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 项目: 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;
}
 
源代码20 项目: openjdk-jdk9   文件: DataFlavorUtil.java
public int compare(DataFlavor flavor1, DataFlavor flavor2) {
    if (flavor1.equals(flavor2)) {
        return 0;
    }

    int comp;

    String primaryType1 = flavor1.getPrimaryType();
    String subType1 = flavor1.getSubType();
    String mimeType1 = primaryType1 + "/" + subType1;
    Class<?> class1 = flavor1.getRepresentationClass();

    String primaryType2 = flavor2.getPrimaryType();
    String subType2 = flavor2.getSubType();
    String mimeType2 = primaryType2 + "/" + subType2;
    Class<?> class2 = flavor2.getRepresentationClass();

    if (flavor1.isFlavorTextType() && flavor2.isFlavorTextType()) {
        // First, compare MIME types
        comp = compareIndices(textTypes, mimeType1, mimeType2, UNKNOWN_OBJECT_LOSES);
        if (comp != 0) {
            return comp;
        }

        // Only need to test one flavor because they both have the
        // same MIME type. Also don't need to worry about accidentally
        // passing stringFlavor because either
        //   1. Both flavors are stringFlavor, in which case the
        //      equality test at the top of the function succeeded.
        //   2. Only one flavor is stringFlavor, in which case the MIME
        //      type comparison returned a non-zero value.
        if (doesSubtypeSupportCharset(flavor1)) {
            // Next, prefer the decoded text representations of Reader,
            // String, CharBuffer, and [C, in that order.
            comp = compareIndices(decodedTextRepresentations, class1,
                    class2, UNKNOWN_OBJECT_LOSES);
            if (comp != 0) {
                return comp;
            }

            // Next, compare charsets
            comp = CharsetComparator.INSTANCE.compare(getTextCharset(flavor1),
                    getTextCharset(flavor2));
            if (comp != 0) {
                return comp;
            }
        }

        // Finally, prefer the encoded text representations of
        // InputStream, ByteBuffer, and [B, in that order.
        comp = compareIndices(encodedTextRepresentations, class1,
                class2, UNKNOWN_OBJECT_LOSES);
        if (comp != 0) {
            return comp;
        }
    } else {
        // First, prefer text types
        if (flavor1.isFlavorTextType()) {
            return 1;
        }

        if (flavor2.isFlavorTextType()) {
            return -1;
        }

        // Next, prefer application types.
        comp = compareIndices(primaryTypes, primaryType1, primaryType2,
                UNKNOWN_OBJECT_LOSES);
        if (comp != 0) {
            return comp;
        }

        // Next, look for application/x-java-* types. Prefer unknown
        // MIME types because if the user provides his own data flavor,
        // it will likely be the most descriptive one.
        comp = compareIndices(exactTypes, mimeType1, mimeType2,
                UNKNOWN_OBJECT_WINS);
        if (comp != 0) {
            return comp;
        }

        // Finally, prefer the representation classes of Remote,
        // Serializable, and InputStream, in that order.
        comp = compareIndices(nonTextRepresentations, class1, class2,
                UNKNOWN_OBJECT_LOSES);
        if (comp != 0) {
            return comp;
        }
    }

    // The flavours are not equal but still not distinguishable.
    // Compare String representations in alphabetical order
    return flavor1.getMimeType().compareTo(flavor2.getMimeType());
}