|
|
|
@@ -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; |
|
|
|
} |
|
|
|
} |