Browse Source

Generator of a UTF-8 character decoder that repairs coding defects.

tags/Production_5_21_2012
ymlam 13 years ago
parent
commit
fb95ae73a1
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      src/altk/common/engine/util/UTF8BenevolentDecoder.java

+ 27
- 0
src/altk/common/engine/util/UTF8BenevolentDecoder.java View File

@@ -0,0 +1,27 @@
package altk.common.engine.util;

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;

/**
* The only method returns a UTF-8 CharsetDecoder object that repairs malformed or
* unmappable UTF-8 characters as it decodes an input byte stream.
* @author Yuk-Ming
*
*/
public class UTF8BenevolentDecoder
{
/**
* @return a UTF-8 CharsetDecoder object that repairs malformed or
* unmappable UTF-8 characters as it decodes an input byte stream
*/
public static CharsetDecoder getDecoder()
{
Charset utf8Charset = Charset.forName("UTF-8");
CharsetDecoder utf8Decoder = utf8Charset.newDecoder();
// Clean content off bad UTF-8 characters.
utf8Decoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
return utf8Decoder;
}
}

Loading…
Cancel
Save