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