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.concurrent.ConcurrentHashMap; |
25 |
|
27 |
|
26 |
/** Efficient conversion of bytes to character . |
28 |
/** Efficient conversion of bytes to character . |
27 |
* |
29 |
* |
Lines 39-44
Link Here
|
39 |
|
41 |
|
40 |
private static org.apache.juli.logging.Log log= |
42 |
private static org.apache.juli.logging.Log log= |
41 |
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); |
43 |
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); |
|
|
44 |
|
45 |
private static final ConcurrentHashMap<String, Charset> encodingToCharsetCache = |
46 |
new ConcurrentHashMap<String, Charset>(); |
42 |
|
47 |
|
43 |
private IntermediateInputStream iis; |
48 |
private IntermediateInputStream iis; |
44 |
private ReadConvertor conv; |
49 |
private ReadConvertor conv; |
Lines 114-120
Link Here
|
114 |
{ |
119 |
{ |
115 |
// destroy the reader/iis |
120 |
// destroy the reader/iis |
116 |
iis=new IntermediateInputStream(); |
121 |
iis=new IntermediateInputStream(); |
117 |
conv=new ReadConvertor( iis, encoding ); |
122 |
conv=new ReadConvertor( iis, getCharset(encoding) ); |
118 |
} |
123 |
} |
119 |
|
124 |
|
120 |
private final int debug=0; |
125 |
private final int debug=0; |
Lines 123-128
Link Here
|
123 |
log.debug("B2CConverter: " + s ); |
128 |
log.debug("B2CConverter: " + s ); |
124 |
} |
129 |
} |
125 |
|
130 |
|
|
|
131 |
public static Charset getCharset(String enc) { |
132 |
Charset charset = encodingToCharsetCache.get(enc); |
133 |
if (charset == null) { |
134 |
charset = Charset.forName(enc); |
135 |
encodingToCharsetCache.put(enc, charset); |
136 |
} |
137 |
return charset; |
138 |
} |
139 |
|
126 |
// -------------------- Not used - the speed improvemnt is quite small |
140 |
// -------------------- Not used - the speed improvemnt is quite small |
127 |
|
141 |
|
128 |
/* |
142 |
/* |
Lines 192-201
Link Here
|
192 |
|
206 |
|
193 |
/** Create a converter. |
207 |
/** Create a converter. |
194 |
*/ |
208 |
*/ |
195 |
public ReadConvertor( IntermediateInputStream in, String enc ) |
209 |
public ReadConvertor( IntermediateInputStream in, Charset charset ) |
196 |
throws UnsupportedEncodingException |
|
|
197 |
{ |
210 |
{ |
198 |
super( in, enc ); |
211 |
super( in, charset ); |
199 |
} |
212 |
} |
200 |
|
213 |
|
201 |
/** Overriden - will do nothing but reset internal state. |
214 |
/** Overriden - will do nothing but reset internal state. |
Lines 224-229
Link Here
|
224 |
} catch(IOException ioe){ |
237 |
} catch(IOException ioe){ |
225 |
} |
238 |
} |
226 |
} |
239 |
} |
|
|
240 |
|
227 |
} |
241 |
} |
228 |
|
242 |
|
229 |
|
243 |
|