将字符串从EBCDIC转换为Unicode/UTF8 [英] Convert String from EBCDIC to Unicode / UTF8
问题描述
我能够将消息从Java
发送到AS400
上的Websphere MQ
.如果我从WinXP
发送消息,则使用任何可访问的Locale
都没有区别,包括完整的语言本地化;英文Locale
也没有问题.正确的编码很重要,只有以下代码行:
I'm able to send messages from Java
to Websphere MQ
on AS400
. If I send messages from WinXP
, there is no difference if I use any accessible Locale
, including full Language Localization; nor is there a problem with English Locale
. Important for correct encoding is only this code line:
msgId.characterSet = 1208;
很遗憾,这是无效的.我要从MQ Queue
接收消息的情况有所不同.
Infortunately, it's not valid. There are differences in the case that I want to take the message from MQ Queue
.
-
如果我是从Windows OS的
MQ Queue
那里收到消息的(英语,没有任何语言包),我可以String
格式从MQ Queue
接收消息.
In the case that I get message from
MQ Queue
from Windows OS (English without any of Language Pack), I'm able to take message fromMQ Queue
inString
form.
如果Windows操作系统使用某些语言包进行了完全本地化,我会收到一个例外情况
In the case that Windows OS is Full Localized with some of Language Pack, I am receiving an exception
Exception occured while to message buffer :
java.io.UnsupportedEncodingException: Cp870
从代码中删除(从尝试-捕获-最终阻止中删除了balast)
from code (removed balast from try - catch - finally block)
try {
Class.forName("com.ibm.mq.MQEnvironment");
MQEnvironment.hostname = hostname;
MQEnvironment.port = port1;
MQEnvironment.channel = channel;
MQEnvironment.userID = userID;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
try {
qmgr1 = new MQQueueManager(qmanager);
MQGetMessageOptions gmo = new MQGetMessageOptions();
int openOptions2 = MQC.MQOO_INPUT_SHARED;
gmo.options = MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
gmo.options = MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
gmo.options = MQC.MQGMO_WAIT; //Wait until message arrives
gmo.waitInterval = 3000;
getq = qmgr1.accessQueue(responseQueue, openOptions2);
while (true) {
try {
responseFromQUEUE = "";
MQMessage msgId = new MQMessage();
//putmsg.characterSet = 437;// Set code page to ASCII
//putmsg.characterSet = 1200;// Set code page to UNICODE
msgId.characterSet = 1208;
getq.get(msgId, gmo);
String str = msgId.readLine();
//responseFromQUEUE = CpConv.tf870to1250(msgId.readLine());
//own EncodePage doesn't works too
if (responseFromQUEUE.length() == 0) {
break;
}
} catch (MQException mqx) {
if (mqx.reasonCode == EMPTY_QUEUE) {
} else {
}
}
}
} catch (MQException mqx) {
} finally {
}
} catch (IOException ex) {
} catch (ClassNotFoundException e) {
}
请
-
是否有一些参数,我想在那里从
MQMessage#readLine()
我的问题只是关于String
转换
我对MQMessage#getBytes
推荐答案
CP870是EBCDIC主机代码页.发生异常时,您要将Windows更改到什么语言环境?更改本地后,您仍然使用msgId.characterSet = 1208;
吗?看来Java库无法将CP870中的传入消息转换为当前语言环境.
CP870 is EBCDIC host code page. To what locale are you changing the Windows to when the exception occurs? Do you still use msgId.characterSet = 1208;
after the local is changed? It looks like Java libraries are unable to convert the incoming message that is in CP870 to your current locale.
更改语言环境时,请检查什么是Windows代码页,并查看1208是否正确用于
Check what is the Windows code page when you change the locale and see if 1208 is correct for msgId.characterSet.
这篇关于将字符串从EBCDIC转换为Unicode/UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!