Java 中的 UTF-8 到 EBCDIC
我们的要求是将 EBCDIC 文本发送到主机。 我们有一些汉字,因此是 UTF8 格式。 那么,有没有办法将UTF-8字符转换为EBCDIC呢?
谢谢, 拉吉·莫汉
Our requirement is to send EBCDIC text to mainframe. We have some chinese characters thus UTF8 format.
So, is there a way to convert the UTF-8 characters to EBCDIC?
Thanks,
Raj Mohan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您的目标系统是 IBM 大型机或中型机,它完全支持内置于其 JVM 中的所有 EBCDIC 编码,作为名为 CPxxxx 的编码,对应于 IBM CCSID(CP 代表代码页)。 您需要在主机端进行翻译,因为客户端没有必要的编码支持。
由于 Unicode 是 DBCS 及更高版本,并且支持所有已知字符,因此您可能会针对多种 EBCDIC 编码; 所以你可能会以某种方式配置这些编码。 尝试仅让客户端使用 Unicode(UTF-8、UTF-16 等),并在数据到达主机和/或离开主机系统时完成转换。
除了需要在主机端进行翻译之外,其机制与任何 Java 翻译相同; 例如 new String(bytes,encoding) 和 String.getBytes(encoding),以及各种 NIO 和 writer 类。 确实没有什么神奇之处 - 这与 ISO 8859-x 和 Unicode 或任何其他 SBCS(或有限的 DBCS)之间的转换没有什么不同。
例如:
您可以在 上找到更多信息IBM 的文档网站。
Assuming your target system is an IBM mainframe or midrange, it has full support for all of the EBCDIC encodings built into it's JVM as encodings named CPxxxx, corresponding to the IBM CCSID's (CP stands for code-page). You will need to do the translations on the host-side since the client side will not have the necessary encoding support.
Since Unicode is DBCS and greater, and supports every known character, you will likely be targeting multiple EBCDIC encodings; so you will likely configure those encodings in some way. Try to have your client Unicode (UTF-8, UTF-16, etc) only, with the translations being done as data arrives on the host and/or leaves the host system.
Other than needing to do translations host-side, the mechanics are the same as any Java translation; e.g. new String(bytes,encoding) and String.getBytes(encoding), and the various NIO and writer classes. There's really no magic - it's no different than translating between, say, ISO 8859-x and Unicode, or any other SBCS (or limited DBCS).
For example:
You can find more information on IBM's documentation website.
EBCDIC 有许多 8 位代码页。 其中许多都受 VM 支持。 看一下
Charset.availableCharsets().keySet()
,EBCDIC 页面被命名为IBM...
(还有像cp500
这样的别名)对于IBM500
,您可以通过Charset.forName("IBM500").aliases()
看到。有两个问题:
首先,请查看此方法。 对于第二个,尝试所需的目标运行时;-)
EBCDIC has many 8-Bit Codepages. Many of them are supported by the VM. Have a look at
Charset.availableCharsets().keySet()
, the EBCDIC pages are namedIBM...
(there are aliases likecp500
forIBM500
as you can see byCharset.forName("IBM500").aliases()
).There are two problems:
For the first, have a look at this approach. For the second, have a try on the desired target runtime ;-)
您始终可以使用 IBM Toolbox for Java (JTOpen),特别是
com.ibm jt400.jar 中的 .as400.access.AS400Text
类。它如下:
我使用了代码页 420 及其相应的编码 CP420 的 java 表示形式,此代码页用于阿拉伯文本,因此,您应该选择适合中文文本的代码页。
You can always make use of the IBM Toolbox for Java (JTOpen), specifically the
com.ibm.as400.access.AS400Text
class in the jt400.jar.It goes as follows:
I used the code-page 420 and its corresponding java representation of the encoding CP420, this code-page is used for Arabic text, so, you should pick the suitable code-page for Chinese text.
对于中端 AS/400(现在是 IBM i),最好的选择是使用 IBM Java Toolkit (jt400.jar),它可以透明地完成所有这些事情(也许稍微暗示一下)。
请注意,在 Java 内部,字符是 16 位值,而不是 UTF-8(即编码)。
For the midrange AS/400 (IBM i these days) the best bet is to use the IBM Java Toolkit (jt400.jar) which does all these things transparently (perhaps slightly hinted).
Please note that inside Java a character is a 16 bit value, not an UTF-8 (that is an encoding).