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

📄 systemflavormap.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        if (strictKeyValueSeparators.                                indexOf(line.charAt(valueIndex)) != -1) {                            valueIndex++;                        }                    }                    // Skip over white space after other separators if any                    while (valueIndex < len) {                        if (whiteSpaceChars.                                indexOf(line.charAt(valueIndex)) == -1) {                            break;                        }                        valueIndex++;                    }                    String key = line.substring(keyStart, separatorIndex);                    String value = (separatorIndex < len)                        ? line.substring(valueIndex, len)                        : "";                    // Convert then store key and value                    key = loadConvert(key);                    value = loadConvert(value);                    try {                        MimeType mime = new MimeType(value);                        if ("text".equals(mime.getPrimaryType())) {                            String charset = mime.getParameter("charset");                            if (DataTransferer.doesSubtypeSupportCharset                                    (mime.getSubType(), charset))                            {                                // We need to store the charset and eoln                                // parameters, if any, so that the                                // DataTransferer will have this information                                // for conversion into the native format.                                DataTransferer transferer =                                    DataTransferer.getInstance();                                if (transferer != null) {                                    transferer.registerTextFlavorProperties                                        (key, charset,                                         mime.getParameter("eoln"),                                         mime.getParameter("terminators"));                                }                            }                            // But don't store any of these parameters in the                            // DataFlavor itself for any text natives (even                            // non-charset ones). The SystemFlavorMap will                            // synthesize the appropriate mappings later.                            mime.removeParameter("charset");                            mime.removeParameter("class");                            mime.removeParameter("eoln");                            mime.removeParameter("terminators");                            value = mime.toString();                        }                    } catch (MimeTypeParseException e) {                        e.printStackTrace();                        continue;                    }                    DataFlavor flavor;                    try {                        flavor = new DataFlavor(value);                    } catch (Exception e) {                        try {                            flavor = new DataFlavor(value, (String)null);                        } catch (Exception ee) {                            ee.printStackTrace();                            continue;                        }                    }                    // For text/* flavors, store mappings in separate maps to                    // enable dynamic mapping generation at a run-time.                    if ("text".equals(flavor.getPrimaryType())) {                        store(value, key, flavorToNative);                        store(key, value, nativeToFlavor);                    } else {                        store(flavor, key, flavorToNative);                        store(key, flavor, nativeToFlavor);                    }                }            }        }    }    /**     * Copied from java.util.Properties.     */    private boolean continueLine (String line) {        int slashCount = 0;        int index = line.length() - 1;        while((index >= 0) && (line.charAt(index--) == '\\')) {            slashCount++;        }        return (slashCount % 2 == 1);    }    /**     * Copied from java.util.Properties.     */    private String loadConvert(String theString) {        char aChar;        int len = theString.length();        StringBuffer outBuffer = new StringBuffer(len);        for (int x = 0; x < len; ) {            aChar = theString.charAt(x++);            if (aChar == '\\') {                aChar = theString.charAt(x++);                if (aChar == 'u') {                    // Read the xxxx                    int value = 0;                    for (int i = 0; i < 4; i++) {                        aChar = theString.charAt(x++);                        switch (aChar) {                          case '0': case '1': case '2': case '3': case '4':                          case '5': case '6': case '7': case '8': case '9': {                             value = (value << 4) + aChar - '0';                             break;                          }                          case 'a': case 'b': case 'c':                          case 'd': case 'e': case 'f': {                             value = (value << 4) + 10 + aChar - 'a';                             break;                          }                          case 'A': case 'B': case 'C':                          case 'D': case 'E': case 'F': {                             value = (value << 4) + 10 + aChar - 'A';                             break;                          }                          default: {                              throw new IllegalArgumentException(                                           "Malformed \\uxxxx encoding.");                          }                        }                    }                    outBuffer.append((char)value);                } else {                    if (aChar == 't') {                        aChar = '\t';                    } else if (aChar == 'r') {                        aChar = '\r';                    } else if (aChar == 'n') {                        aChar = '\n';                    } else if (aChar == 'f') {                        aChar = '\f';                    }                    outBuffer.append(aChar);                }            } else {                outBuffer.append(aChar);            }        }        return outBuffer.toString();    }    /**     * Stores the listed object under the specified hash key in map. Unlike a     * standard map, the listed object will not replace any object already at     * the appropriate Map location, but rather will be appended to a List     * stored in that location.     */    private void store(Object hashed, Object listed, Map map) {        List list = (List)map.get(hashed);        if (list == null) {            list = new ArrayList(1);            map.put(hashed, list);        }        if (!list.contains(listed)) {            list.add(listed);        }    }    /**     * Semantically equivalent to 'nativeToFlavor.get(nat)'. This method     * handles the case where 'nat' is not found in 'nativeToFlavor'. In that     * case, a new DataFlavor is synthesized, stored, and returned, if and     * only if the specified native is encoded as a Java MIME type.     */    private List nativeToFlavorLookup(String nat) {        List flavors = (List)nativeToFlavor.get(nat);        if (flavors == null && isJavaMIMEType(nat)) {            String decoded = decodeJavaMIMEType(nat);            DataFlavor flavor = null;            try {                flavor = new DataFlavor(decoded);            } catch (Exception e) {                System.err.println("Exception \"" + e.getClass().getName() +                                   ": " + e.getMessage()  +                                   "\"while constructing DataFlavor for: " +                                   decoded);            }            if (flavor != null) {                flavors = new ArrayList(1);                nativeToFlavor.put(nat, flavors);                flavors.add(flavor);                getFlavorsForNativeCache.remove(nat);                getFlavorsForNativeCache.remove(null);                List natives = (List)flavorToNative.get(flavor);                if (natives == null) {                    natives = new ArrayList(1);                    flavorToNative.put(flavor, natives);                }                natives.add(nat);                getNativesForFlavorCache.remove(flavor);                getNativesForFlavorCache.remove(null);            }        }        return (flavors != null) ? flavors : new ArrayList(0);    }    /**     * Semantically equivalent to 'flavorToNative.get(flav)'. This method     * handles the case where 'flav' is not found in 'flavorToNative' depending     * on the value of passes 'synthesize' parameter. If 'synthesize' is     * SYNTHESIZE_IF_NOT_FOUND a native is synthesized, stored, and returned by     * encoding the DataFlavor's MIME type. Otherwise an empty List is returned     * and 'flavorToNative' remains unaffected.     */    private List flavorToNativeLookup(final DataFlavor flav,                                       final boolean synthesize) {        List natives = (List)flavorToNative.get(flav);        if (natives == null) {            if (synthesize) {                String encoded = encodeDataFlavor(flav);                natives = new ArrayList(1);                flavorToNative.put(flav, natives);                natives.add(encoded);                getNativesForFlavorCache.remove(flav);                getNativesForFlavorCache.remove(null);                List flavors = (List)nativeToFlavor.get(encoded);                if (flavors == null) {                    flavors = new ArrayList(1);                    nativeToFlavor.put(encoded, flavors);                }                flavors.add(flav);                getFlavorsForNativeCache.remove(encoded);                getFlavorsForNativeCache.remove(null);            } else {                natives = new ArrayList(0);            }        }        return natives;    }    /**     * Returns a <code>List</code> of <code>String</code> natives to which the     * specified <code>DataFlavor</code> can be translated by the data transfer     * subsystem. The <code>List</code> will be sorted from best native to     * worst. That is, the first native will best reflect data in the specified     * flavor to the underlying native platform.     * <p>     * If the specified <code>DataFlavor</code> is previously unknown to the     * data transfer subsystem, then invoking this method will establish a     * mapping in both directions between the specified <code>DataFlavor</code>     * and an encoded version of its MIME type as its native.     *     * @param flav the <code>DataFlavor</code> whose corresponding natives     *        should be returned. If <code>null</code> is specified, all     *        natives currently known to the data transfer subsystem are     *        returned in a non-deterministic order.     * @return a <code>java.util.List</code> of <code>java.lang.String</code>     *         objects which are platform-specific representations of platform-     *         specific data formats     *     * @see #encodeDataFlavor     * @since 1.4     */    public synchronized List getNativesForFlavor(DataFlavor flav) {        List retval = null;        // Check cache, even for null flav        SoftReference ref = (SoftReference)getNativesForFlavorCache.get(flav);        if (ref != null) {            retval = (List)ref.get();            if (retval != null) {                // Create a copy, because client code can modify the returned                // list.                return new ArrayList(retval);            }        }        if (flav == null) {            retval = new ArrayList(nativeToFlavor.keySet());        } else if (disabledMappingGenerationKeys.contains(flav)) {            // In this case we shouldn't synthesize a native for this flavor,            // since its mappings were explicitly specified.            retval = flavorToNativeLookup(flav, !SYNTHESIZE_IF_NOT_FOUND);        } else if (DataTransferer.isFlavorCharsetTextType(flav)) {

⌨️ 快捷键说明

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