--- old/src/share/classes/sun/awt/datatransfer/DataTransferer.java 2014-04-18 11:00:58.000000000 +0400 +++ new/src/share/classes/sun/awt/datatransfer/DataTransferer.java 2014-04-18 11:00:58.000000000 +0400 @@ -57,6 +57,7 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.lang.reflect.Constructor; @@ -164,7 +165,7 @@ tempSet.add("UTF-16BE"); tempSet.add("UTF-16LE"); tempSet.add("UTF-16"); - tempSet.add(getDefaultTextCharset()); + tempSet.add(Charset.defaultCharset().name()); return Collections.unmodifiableSortedSet(tempSet); } } @@ -178,12 +179,6 @@ private static final Map textMIMESubtypeCharsetSupport; /** - * Cache of the platform default encoding as specified in the - * "file.encoding" system property. - */ - private static String defaultEncoding; - - /** * A collection of all natives listed in flavormap.properties with * a primary MIME type of "text". */ @@ -281,17 +276,7 @@ String encoding = flavor.getParameter("charset"); - return (encoding != null) ? encoding : getDefaultTextCharset(); - } - - /** - * Returns the platform's default character encoding. - */ - public static String getDefaultTextCharset() { - if (defaultEncoding != null) { - return defaultEncoding; - } - return defaultEncoding = Charset.defaultCharset().name(); + return (encoding != null) ? encoding : Charset.defaultCharset().name(); } /** @@ -485,7 +470,7 @@ textNatives.add(format); nativeCharsets.put(format, (charset != null && charset.length() != 0) - ? charset : getDefaultTextCharset()); + ? charset : Charset.defaultCharset().name()); if (eoln != null && eoln.length() != 0 && !eoln.equals("\n")) { nativeEOLNs.put(format, eoln); } @@ -786,19 +771,17 @@ * clipboard string encoding/decoding, basing on clipboard * format and localeTransferable(on decoding, if available) */ - private String getBestCharsetForTextFormat(Long lFormat, + protected String getBestCharsetForTextFormat(Long lFormat, Transferable localeTransferable) throws IOException { String charset = null; if (localeTransferable != null && isLocaleDependentTextFormat(lFormat) && - localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) - { + localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) { try { - charset = new String( - (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor), - "UTF-8" - ); + byte[] charsetNameBytes = (byte[])localeTransferable + .getTransferData(javaTextEncodingFlavor); + charset = new String(charsetNameBytes, StandardCharsets.UTF_8); } catch (UnsupportedFlavorException cannotHappen) { } } else { @@ -806,7 +789,7 @@ } if (charset == null) { // Only happens when we have a custom text type. - charset = getDefaultTextCharset(); + charset = Charset.defaultCharset().name(); } return charset; } @@ -1731,28 +1714,8 @@ { Long lFormat = format; - String sourceEncoding = null; - if (isLocaleDependentTextFormat(format) && - localeTransferable != null && - localeTransferable. - isDataFlavorSupported(javaTextEncodingFlavor)) - { - try { - sourceEncoding = new String((byte[])localeTransferable. - getTransferData(javaTextEncodingFlavor), - "UTF-8"); - } catch (UnsupportedFlavorException cannotHappen) { - } - } else { - sourceEncoding = getCharsetForTextFormat(lFormat); - } - - if (sourceEncoding == null) { - // Only happens when we have a custom text type. - sourceEncoding = getDefaultTextCharset(); - } - wrapped = new BufferedReader - (new InputStreamReader(bytestream, sourceEncoding)); + String sourceEncoding = getBestCharsetForTextFormat(format, localeTransferable); + wrapped = new BufferedReader(new InputStreamReader(bytestream, sourceEncoding)); if (targetEncoding == null) { // Throw NullPointerException for compatibility with the former @@ -2333,7 +2296,6 @@ */ public static class CharsetComparator extends IndexedComparator { private static final Map charsets; - private static final String defaultEncoding; private static final Integer DEFAULT_CHARSET_INDEX = 2; private static final Integer OTHER_CHARSET_INDEX = 1; @@ -2354,8 +2316,7 @@ // US-ASCII is the worst charset supported charsetsMap.put(canonicalName("US-ASCII"), WORST_CHARSET_INDEX); - defaultEncoding = DataTransferer.canonicalName(DataTransferer.getDefaultTextCharset()); - charsetsMap.putIfAbsent(defaultEncoding, DEFAULT_CHARSET_INDEX); + charsetsMap.putIfAbsent(Charset.defaultCharset().name(), DEFAULT_CHARSET_INDEX); charsetsMap.put(UNSUPPORTED_CHARSET, UNSUPPORTED_CHARSET_INDEX);