98 String csn = canonicalize(toLower(charsetName)); 99 100 // Check cache first 101 Charset cs = cache.get(csn); 102 if (cs != null) 103 return cs; 104 105 // Do we even support this charset? 106 String cln = classMap.get(csn); 107 if (cln == null) 108 return null; 109 110 if (cln.equals("US_ASCII")) { 111 cs = new US_ASCII(); 112 cache.put(csn, cs); 113 return cs; 114 } 115 116 // Instantiate the charset and cache it 117 try { 118 Class<?> c = Class.forName(packagePrefix + "." + cln, 119 true, 120 this.getClass().getClassLoader()); 121 cs = (Charset)c.newInstance(); 122 cache.put(csn, cs); 123 return cs; 124 } catch (ClassNotFoundException | 125 IllegalAccessException | 126 InstantiationException x) { 127 return null; 128 } 129 } 130 131 public final Charset charsetForName(String charsetName) { 132 synchronized (this) { 133 return lookup(canonicalize(charsetName)); 134 } 135 } 136 137 public final Iterator<Charset> charsets() { 138 139 return new Iterator<Charset>() { 140 141 Iterator<String> i = classMap.keySet().iterator(); | 98 String csn = canonicalize(toLower(charsetName)); 99 100 // Check cache first 101 Charset cs = cache.get(csn); 102 if (cs != null) 103 return cs; 104 105 // Do we even support this charset? 106 String cln = classMap.get(csn); 107 if (cln == null) 108 return null; 109 110 if (cln.equals("US_ASCII")) { 111 cs = new US_ASCII(); 112 cache.put(csn, cs); 113 return cs; 114 } 115 116 // Instantiate the charset and cache it 117 try { 118 @SuppressWarnings("deprecation") 119 Object o= Class.forName(packagePrefix + "." + cln, 120 true, 121 this.getClass().getClassLoader()).newInstance(); 122 cs = (Charset)o; 123 cache.put(csn, cs); 124 return cs; 125 } catch (ClassNotFoundException | 126 IllegalAccessException | 127 InstantiationException x) { 128 return null; 129 } 130 } 131 132 public final Charset charsetForName(String charsetName) { 133 synchronized (this) { 134 return lookup(canonicalize(charsetName)); 135 } 136 } 137 138 public final Iterator<Charset> charsets() { 139 140 return new Iterator<Charset>() { 141 142 Iterator<String> i = classMap.keySet().iterator(); |