How to define a new Charset in Java/Android?(如何在 Java/Android 中定义一个新的字符集?)
问题描述
在台湾,我们有一种称为Unicode At One (UAO)"的字符编码,它是 BIG-5 的扩展,但 Java 和 Android 不支持.
代码页位于 http://moztw.org/docs/big5/table/uao241-b2u.txt
in Taiwan we have a character encoding called "Unicode At One (UAO)", which is an extension to BIG-5 but is not supported by Java and Android.
The code page is in http://moztw.org/docs/big5/table/uao241-b2u.txt
我的问题是,如何使用这个 Charset 构建一个包含字节数组数据的 String 对象?
我想我会扩展 String 类并在其中做一些事情,但我不知道如何创建一个新的 Charset.
My question is, how can I build a String object with byte array data, using this Charset?
I guess I will extend the String class and do something in it, but I have no idea how to create a new Charset.
推荐答案
您可以添加自己的 Charset
通过编写 CharsetProvider
并通过服务发现机制注册它.
You can add your own Charset
implementation by writing a CharsetProvider
and registering it via the service discovery mechanism.
您需要扩展 Charset
并实现其 newDecoder
和 newEncoder
方法返回适当的CharsetDecoder
和 CharsetEncoder
.
You'll need to extend Charset
and implements its newDecoder
and newEncoder
methods to return an appropriate CharsetDecoder
and CharsetEncoder
respectively.
这篇关于如何在 Java/Android 中定义一个新的字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!