329 |
return true; |
return true; |
330 |
} |
} |
331 |
|
|
332 |
public final ByteBuffer encode (CharBuffer cb) |
// NB: This implementation serializes different threads calling |
333 |
|
// Charset.encode(), a potential performance problem. It might |
334 |
|
// be better to remove the cache, or use ThreadLocal to cache on |
335 |
|
// a per-thread basis. |
336 |
|
public final synchronized ByteBuffer encode (CharBuffer cb) |
337 |
{ |
{ |
338 |
try |
try |
339 |
{ |
{ |
340 |
// NB: This implementation serializes different threads calling |
if (cachedEncoder == null) |
341 |
// Charset.encode(), a potential performance problem. It might |
{ |
342 |
// be better to remove the cache, or use ThreadLocal to cache on |
cachedEncoder = newEncoder () |
343 |
// a per-thread basis. |
.onMalformedInput (CodingErrorAction.REPLACE) |
344 |
synchronized (Charset.class) |
.onUnmappableCharacter (CodingErrorAction.REPLACE); |
345 |
{ |
} else |
346 |
if (cachedEncoder == null) |
cachedEncoder.reset(); |
347 |
{ |
return cachedEncoder.encode (cb); |
|
cachedEncoder = newEncoder () |
|
|
.onMalformedInput (CodingErrorAction.REPLACE) |
|
|
.onUnmappableCharacter (CodingErrorAction.REPLACE); |
|
|
} else |
|
|
cachedEncoder.reset(); |
|
|
return cachedEncoder.encode (cb); |
|
|
} |
|
348 |
} |
} |
349 |
catch (CharacterCodingException e) |
catch (CharacterCodingException e) |
350 |
{ |
{ |
357 |
return encode (CharBuffer.wrap (str)); |
return encode (CharBuffer.wrap (str)); |
358 |
} |
} |
359 |
|
|
360 |
public final CharBuffer decode (ByteBuffer bb) |
// NB: This implementation serializes different threads calling |
361 |
|
// Charset.decode(), a potential performance problem. It might |
362 |
|
// be better to remove the cache, or use ThreadLocal to cache on |
363 |
|
// a per-thread basis. |
364 |
|
public final synchronized CharBuffer decode (ByteBuffer bb) |
365 |
{ |
{ |
366 |
try |
try |
367 |
{ |
{ |
368 |
// NB: This implementation serializes different threads calling |
if (cachedDecoder == null) |
369 |
// Charset.decode(), a potential performance problem. It might |
{ |
370 |
// be better to remove the cache, or use ThreadLocal to cache on |
cachedDecoder = newDecoder () |
371 |
// a per-thread basis. |
.onMalformedInput (CodingErrorAction.REPLACE) |
372 |
synchronized (Charset.class) |
.onUnmappableCharacter (CodingErrorAction.REPLACE); |
373 |
{ |
} else |
374 |
if (cachedDecoder == null) |
cachedDecoder.reset(); |
|
{ |
|
|
cachedDecoder = newDecoder () |
|
|
.onMalformedInput (CodingErrorAction.REPLACE) |
|
|
.onUnmappableCharacter (CodingErrorAction.REPLACE); |
|
|
} else |
|
|
cachedDecoder.reset(); |
|
375 |
|
|
376 |
return cachedDecoder.decode (bb); |
return cachedDecoder.decode (bb); |
|
} |
|
377 |
} |
} |
378 |
catch (CharacterCodingException e) |
catch (CharacterCodingException e) |
379 |
{ |
{ |