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