diff -r 588d5bf7a560 -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/nio/charset/Charset.java --- a/rt/emul/compact/src/main/java/java/nio/charset/Charset.java Thu Oct 03 15:40:35 2013 +0200 +++ b/rt/emul/compact/src/main/java/java/nio/charset/Charset.java Fri Oct 04 15:02:17 2013 +0200 @@ -25,27 +25,16 @@ package java.nio.charset; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.spi.CharsetProvider; -import java.security.AccessController; -import java.security.AccessControlException; -import java.security.PrivilegedAction; +//import java.nio.ByteBuffer; +//import java.nio.CharBuffer; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; -import java.util.ServiceLoader; -import java.util.ServiceConfigurationError; import java.util.SortedMap; import java.util.TreeMap; -import sun.misc.ASCIICaseInsensitiveComparator; -import sun.nio.cs.StandardCharsets; -import sun.nio.cs.ThreadLocalCoders; -import sun.security.action.GetPropertyAction; /** @@ -281,17 +270,6 @@ private static volatile String bugLevel = null; - static boolean atBugLevel(String bl) { // package-private - String level = bugLevel; - if (level == null) { - if (!sun.misc.VM.isBooted()) - return false; - bugLevel = level = AccessController.doPrivileged( - new GetPropertyAction("sun.nio.cs.bugLevel", "")); - } - return level.equals(bl); - } - /** * Checks that the given string is a legal charset name.

* @@ -303,10 +281,8 @@ */ private static void checkName(String s) { int n = s.length(); - if (!atBugLevel("1.4")) { if (n == 0) throw new IllegalCharsetNameException(s); - } for (int i = 0; i < n; i++) { char c = s.charAt(i); if (c >= 'A' && c <= 'Z') continue; @@ -321,9 +297,6 @@ } } - /* The standard set of charsets */ - private static CharsetProvider standardProvider = new StandardCharsets(); - // Cache of the most-recently-returned charsets, // along with the names that were used to find them // @@ -340,126 +313,23 @@ // thrown. Should be invoked with full privileges. // private static Iterator providers() { - return new Iterator() { - - ClassLoader cl = ClassLoader.getSystemClassLoader(); - ServiceLoader sl = - ServiceLoader.load(CharsetProvider.class, cl); - Iterator i = sl.iterator(); - - Object next = null; - - private boolean getNext() { - while (next == null) { - try { - if (!i.hasNext()) - return false; - next = i.next(); - } catch (ServiceConfigurationError sce) { - if (sce.getCause() instanceof SecurityException) { - // Ignore security exceptions - continue; - } - throw sce; - } - } - return true; - } - - public boolean hasNext() { - return getNext(); - } - - public Object next() { - if (!getNext()) - throw new NoSuchElementException(); - Object n = next; - next = null; - return n; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - }; + return Collections.emptyIterator(); } // Thread-local gate to prevent recursive provider lookups private static ThreadLocal gate = new ThreadLocal(); private static Charset lookupViaProviders(final String charsetName) { - - // The runtime startup sequence looks up standard charsets as a - // consequence of the VM's invocation of System.initializeSystemClass - // in order to, e.g., set system properties and encode filenames. At - // that point the application class loader has not been initialized, - // however, so we can't look for providers because doing so will cause - // that loader to be prematurely initialized with incomplete - // information. - // - if (!sun.misc.VM.isBooted()) - return null; - - if (gate.get() != null) - // Avoid recursive provider lookups - return null; - try { - gate.set(gate); - - return AccessController.doPrivileged( - new PrivilegedAction() { - public Charset run() { - for (Iterator i = providers(); i.hasNext();) { - CharsetProvider cp = (CharsetProvider)i.next(); - Charset cs = cp.charsetForName(charsetName); - if (cs != null) - return cs; - } - return null; - } - }); - - } finally { - gate.set(null); - } + return null; } /* The extended set of charsets */ private static Object extendedProviderLock = new Object(); private static boolean extendedProviderProbed = false; - private static CharsetProvider extendedProvider = null; - private static void probeExtendedProvider() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - Class epc - = Class.forName("sun.nio.cs.ext.ExtendedCharsets"); - extendedProvider = (CharsetProvider)epc.newInstance(); - } catch (ClassNotFoundException x) { - // Extended charsets not available - // (charsets.jar not present) - } catch (InstantiationException x) { - throw new Error(x); - } catch (IllegalAccessException x) { - throw new Error(x); - } - return null; - } - }); - } private static Charset lookupExtendedCharset(String charsetName) { - CharsetProvider ecp = null; - synchronized (extendedProviderLock) { - if (!extendedProviderProbed) { - probeExtendedProvider(); - extendedProviderProbed = true; - } - ecp = extendedProvider; - } - return (ecp != null) ? ecp.charsetForName(charsetName) : null; + return null; } private static Charset lookup(String charsetName) { @@ -483,15 +353,6 @@ return (Charset)a[1]; } - Charset cs; - if ((cs = standardProvider.charsetForName(charsetName)) != null || - (cs = lookupExtendedCharset(charsetName)) != null || - (cs = lookupViaProviders(charsetName)) != null) - { - cache(charsetName, cs); - return cs; - } - /* Only need to check the name if we didn't find a charset for it */ checkName(charsetName); return null; @@ -581,20 +442,9 @@ * to charset objects */ public static SortedMap availableCharsets() { - return AccessController.doPrivileged( - new PrivilegedAction>() { - public SortedMap run() { - TreeMap m = - new TreeMap( - ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER); - put(standardProvider.charsets(), m); - for (Iterator i = providers(); i.hasNext();) { - CharsetProvider cp = (CharsetProvider)i.next(); - put(cp.charsets(), m); - } - return Collections.unmodifiableSortedMap(m); - } - }); + TreeMap tm = new TreeMap(); + tm.put("UTF-8", Charset.defaultCharset()); + return tm; } private static volatile Charset defaultCharset; @@ -612,15 +462,7 @@ */ public static Charset defaultCharset() { if (defaultCharset == null) { - synchronized (Charset.class) { - String csn = AccessController.doPrivileged( - new GetPropertyAction("file.encoding")); - Charset cs = lookup(csn); - if (cs != null) - defaultCharset = cs; - else - defaultCharset = forName("UTF-8"); - } + defaultCharset = forName("UTF-8"); } return defaultCharset; } @@ -805,16 +647,16 @@ * * @return A char buffer containing the decoded characters */ - public final CharBuffer decode(ByteBuffer bb) { - try { - return ThreadLocalCoders.decoderFor(this) - .onMalformedInput(CodingErrorAction.REPLACE) - .onUnmappableCharacter(CodingErrorAction.REPLACE) - .decode(bb); - } catch (CharacterCodingException x) { - throw new Error(x); // Can't happen - } - } +// public final CharBuffer decode(ByteBuffer bb) { +// try { +// return ThreadLocalCoders.decoderFor(this) +// .onMalformedInput(CodingErrorAction.REPLACE) +// .onUnmappableCharacter(CodingErrorAction.REPLACE) +// .decode(bb); +// } catch (CharacterCodingException x) { +// throw new Error(x); // Can't happen +// } +// } /** * Convenience method that encodes Unicode characters into bytes in this @@ -841,16 +683,16 @@ * * @return A byte buffer containing the encoded characters */ - public final ByteBuffer encode(CharBuffer cb) { - try { - return ThreadLocalCoders.encoderFor(this) - .onMalformedInput(CodingErrorAction.REPLACE) - .onUnmappableCharacter(CodingErrorAction.REPLACE) - .encode(cb); - } catch (CharacterCodingException x) { - throw new Error(x); // Can't happen - } - } +// public final ByteBuffer encode(CharBuffer cb) { +// try { +// return ThreadLocalCoders.encoderFor(this) +// .onMalformedInput(CodingErrorAction.REPLACE) +// .onUnmappableCharacter(CodingErrorAction.REPLACE) +// .encode(cb); +// } catch (CharacterCodingException x) { +// throw new Error(x); // Can't happen +// } +// } /** * Convenience method that encodes a string into bytes in this charset. @@ -865,9 +707,9 @@ * * @return A byte buffer containing the encoded characters */ - public final ByteBuffer encode(String str) { - return encode(CharBuffer.wrap(str)); - } +// public final ByteBuffer encode(String str) { +// return encode(CharBuffer.wrap(str)); +// } /** * Compares this charset to another.