Lines 21-27
Link Here
|
21 |
import java.io.IOException; |
21 |
import java.io.IOException; |
22 |
import java.io.InputStream; |
22 |
import java.io.InputStream; |
23 |
import java.io.InputStreamReader; |
23 |
import java.io.InputStreamReader; |
24 |
import java.io.UnsupportedEncodingException; |
24 |
import java.nio.charset.Charset; |
|
|
25 |
import java.nio.charset.UnsupportedCharsetException; |
26 |
import java.util.Locale; |
27 |
import java.util.concurrent.ConcurrentHashMap; |
25 |
|
28 |
|
26 |
/** Efficient conversion of bytes to character . |
29 |
/** Efficient conversion of bytes to character . |
27 |
* |
30 |
* |
Lines 39-45
Link Here
|
39 |
|
42 |
|
40 |
private static org.apache.juli.logging.Log log= |
43 |
private static org.apache.juli.logging.Log log= |
41 |
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); |
44 |
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); |
|
|
45 |
|
46 |
private static final ConcurrentHashMap<String, Charset> encodingToCharsetCache = |
47 |
new ConcurrentHashMap<String, Charset>(); |
42 |
|
48 |
|
|
|
49 |
static { |
50 |
for (Charset charset: Charset.availableCharsets().values()) { |
51 |
encodingToCharsetCache.put( |
52 |
charset.name().toLowerCase(Locale.US), charset); |
53 |
for (String alias : charset.aliases()) { |
54 |
encodingToCharsetCache.put( |
55 |
alias.toLowerCase(Locale.US), charset); |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
public static Charset getCharset(String enc) { |
61 |
|
62 |
// Encoding names should all be ASCII |
63 |
String lowerCaseEnc = enc.toLowerCase(Locale.US); |
64 |
|
65 |
Charset charset = encodingToCharsetCache.get(lowerCaseEnc); |
66 |
|
67 |
if (charset == null) { |
68 |
// Pre-population of the cache means this must be invalid |
69 |
throw new UnsupportedCharsetException(enc); |
70 |
} |
71 |
return charset; |
72 |
} |
73 |
|
43 |
private IntermediateInputStream iis; |
74 |
private IntermediateInputStream iis; |
44 |
private ReadConvertor conv; |
75 |
private ReadConvertor conv; |
45 |
private String encoding; |
76 |
private String encoding; |
Lines 114-120
Link Here
|
114 |
{ |
145 |
{ |
115 |
// destroy the reader/iis |
146 |
// destroy the reader/iis |
116 |
iis=new IntermediateInputStream(); |
147 |
iis=new IntermediateInputStream(); |
117 |
conv=new ReadConvertor( iis, encoding ); |
148 |
conv=new ReadConvertor( iis, getCharset(encoding) ); |
118 |
} |
149 |
} |
119 |
|
150 |
|
120 |
private final int debug=0; |
151 |
private final int debug=0; |
Lines 192-201
Link Here
|
192 |
|
223 |
|
193 |
/** Create a converter. |
224 |
/** Create a converter. |
194 |
*/ |
225 |
*/ |
195 |
public ReadConvertor( IntermediateInputStream in, String enc ) |
226 |
public ReadConvertor( IntermediateInputStream in, Charset charset ) |
196 |
throws UnsupportedEncodingException |
|
|
197 |
{ |
227 |
{ |
198 |
super( in, enc ); |
228 |
super( in, charset ); |
199 |
} |
229 |
} |
200 |
|
230 |
|
201 |
/** Overriden - will do nothing but reset internal state. |
231 |
/** Overriden - will do nothing but reset internal state. |
Lines 224-229
Link Here
|
224 |
} catch(IOException ioe){ |
254 |
} catch(IOException ioe){ |
225 |
} |
255 |
} |
226 |
} |
256 |
} |
|
|
257 |
|
227 |
} |
258 |
} |
228 |
|
259 |
|
229 |
|
260 |
|