--- java/org/apache/tomcat/util/buf/B2CConverter.java (revision 1138858) +++ java/org/apache/tomcat/util/buf/B2CConverter.java (working copy) @@ -23,9 +23,9 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.UnsupportedCharsetException; -import java.util.concurrent.ConcurrentHashMap; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.SortedMap; /** Efficient conversion of bytes to character . * @@ -44,28 +44,26 @@ private static final org.apache.juli.logging.Log log= org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); - private static final ConcurrentHashMap encodingToCharsetCache = - new ConcurrentHashMap(); + private static final HashMap encodingToCharsetCache = + new HashMap(); + + static { + SortedMap charsets = Charset.availableCharsets(); + for (Entry e : charsets.entrySet()) { + Charset cs = e.getValue(); + encodingToCharsetCache.put(e.getKey().toLowerCase(), cs); + for (String alias : cs.aliases()) { + encodingToCharsetCache.put(alias.toLowerCase(), cs); + } + } + } public static Charset getCharset(String enc) throws UnsupportedEncodingException{ - - Charset charset = encodingToCharsetCache.get(enc); + + Charset charset = encodingToCharsetCache.get(enc.toLowerCase()); if (charset == null) { - try { - charset = Charset.forName(enc); - } catch (IllegalCharsetNameException icne) { - UnsupportedEncodingException uee = - new UnsupportedEncodingException(); - uee.initCause(icne); - throw uee; - } catch (UnsupportedCharsetException uce) { - UnsupportedEncodingException uee = - new UnsupportedEncodingException(); - uee.initCause(uce); - throw uee; - } - encodingToCharsetCache.put(enc, charset); + throw new UnsupportedEncodingException(enc); } return charset; }