简体   繁体   English

从bytes []转换为EBCDIC字符串

[英]Convert from bytes[] to EBCDIC string

I am receiving bytes[] from mainframe MQ. 我正在从大型机MQ接收bytes []。 This bytes[] I am trying to convert to EBCDIC string. 我要将此字节[]转换为EBCDIC字符串。 I am using the following and the sytem just hangs. 我正在使用以下内容,并且系统刚刚挂起。 What could be the issue? 可能是什么问题?

new String(mqmdAccountingToken,"Cp1047");

mqmdAccountingToken is the byte array received from MQ. mqmdAccountingToken是从MQ接收的字节数组。 I feel that the Charset that I have provided is not correct. 我觉得我提供的字符集不正确。 Is there a way to identify the correct charset to use and then convert? 有没有办法确定要使用的正确字符集然后进行转换?

The MQMD AccountingToken field is made up of both binary values and character values set by the queue manager (default behavior), so you need to treat it as a binary field (ie byte[] field) and not a character field. MQMD AccountingToken字段由队列管理器设置的二进制值和字符值组成(默认行为),因此您需要将其视为二进制字段(即byte []字段)而不是字符字段。

If you really want to convert it to some character field then convert it to Hex display characters. 如果您确实要将其转换为某些字符字段,则将其转换为十六进制显示字符。

Evidently one of the main criticisms of EBCDIC early on was its large number of variants. 显然,早期对EBCDIC的主要批评之一是其大量的变体。 You will need to determine, almost certainly outside your program, which variant you have, and use the corresponding character set. 您几乎需要在程序外部确定具有哪种变体,并使用相应的字符集。 The fact that it is from a "mainframe" and MQ does not identify the character set. 它来自“大型机”和MQ的事实不能识别字符集。 You can see the number of possible sets at this IBM site . 您可以在此IBM站点上看到可能的集合数。

Here is how you should be dealing with MQMD AccountingToken field - you convert it from binary data to hex display characters. 这是您应该如何处理MQMD AccountingToken字段的方法-将其从二进制数据转换为十六进制显示字符。

StringBuffer sb = new StringBuffer();
String hex;
for (i=0; i < msg.accountingToken.length; i++)
{
   hex = Integer.toHexString((new Byte(msg.accountingToken[i])).intValue());

   if (hex.length() == 2)
      sb.append(hex);
   else if (hex.length() == 1)
      sb.append("0" + hex);
   else if (hex.length() > 2)
   {
      sb.append(hex.substring(hex.length()-2,hex.length()-1));
      sb.append(hex.substring(hex.length()-1,hex.length()));
   }
}
System.out.println(" AccountingToken: X'" + sb.toString().toUpperCase() + "'");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM