View | Details | Raw Unified | Return to bug 51400
Collapse All | Expand All

(-)java/org/apache/tomcat/util/buf/B2CConverter.java (-21 / +19 lines)
Lines 23-31 Link Here
23
import java.io.InputStreamReader;
23
import java.io.InputStreamReader;
24
import java.io.UnsupportedEncodingException;
24
import java.io.UnsupportedEncodingException;
25
import java.nio.charset.Charset;
25
import java.nio.charset.Charset;
26
import java.nio.charset.IllegalCharsetNameException;
26
import java.util.HashMap;
27
import java.nio.charset.UnsupportedCharsetException;
27
import java.util.Map.Entry;
28
import java.util.concurrent.ConcurrentHashMap;
28
import java.util.SortedMap;
29
29
30
/** Efficient conversion of bytes  to character .
30
/** Efficient conversion of bytes  to character .
31
 *  
31
 *  
Lines 44-71 Link Here
44
    private static final org.apache.juli.logging.Log log=
44
    private static final org.apache.juli.logging.Log log=
45
        org.apache.juli.logging.LogFactory.getLog( B2CConverter.class );
45
        org.apache.juli.logging.LogFactory.getLog( B2CConverter.class );
46
    
46
    
47
    private static final ConcurrentHashMap<String, Charset> encodingToCharsetCache =
47
    private static final HashMap<String, Charset> encodingToCharsetCache =
48
        new ConcurrentHashMap<String, Charset>();
48
        new HashMap<String, Charset>();
49
    
50
    static {
51
        SortedMap<String, Charset> charsets = Charset.availableCharsets();
52
        for (Entry<String, Charset> e : charsets.entrySet()) {
53
            Charset cs = e.getValue();
54
            encodingToCharsetCache.put(e.getKey().toLowerCase(), cs);
55
            for (String alias : cs.aliases()) {
56
                encodingToCharsetCache.put(alias.toLowerCase(), cs);
57
            }
58
        }
59
    }
49
60
50
    public static Charset getCharset(String enc)
61
    public static Charset getCharset(String enc)
51
            throws UnsupportedEncodingException{
62
            throws UnsupportedEncodingException{
52
63
        
53
        Charset charset = encodingToCharsetCache.get(enc);
64
        Charset charset = encodingToCharsetCache.get(enc.toLowerCase());
54
        if (charset == null) {
65
        if (charset == null) {
55
            try {
66
            throw new UnsupportedEncodingException(enc);
56
                charset = Charset.forName(enc);
57
            } catch (IllegalCharsetNameException icne) {
58
                UnsupportedEncodingException uee =
59
                    new UnsupportedEncodingException();
60
                uee.initCause(icne);
61
                throw uee;
62
            } catch (UnsupportedCharsetException uce) {
63
                UnsupportedEncodingException uee =
64
                    new UnsupportedEncodingException();
65
                uee.initCause(uce);
66
                throw uee;
67
            }
68
            encodingToCharsetCache.put(enc, charset);
69
        }
67
        }
70
        return charset;
68
        return charset;
71
    }
69
    }

Return to bug 51400