cancel
Showing results for 
Search instead for 
Did you mean: 

Java UDF help: Hexadecimal to Chinese Unicode converison

Senthilprakash1
Participant
0 Kudos

Hi Experts,

can someone help me in a design solution to convert Hexadecimal Values to Chinese Characters while sending the data to receiver system.

I am not able to get any methods in Java to do the conversion.

Help is appreciated.

Regards,

Prakash.

Accepted Solutions (0)

Answers (3)

Answers (3)

srikanth_srinivasan3
Active Participant
0 Kudos

Prakash,

This can help a bit:

String chinese = "\u4E2D\u56FD";

File file1 = new File("testing.txt");

OutputStream out = new FileOutputStream(file1);

Writer writer1=new OutputStreamWriter(out, Charset.forName("UTF-8"));

writer1.write(chinese);

writer1.close();

out.close();

-

Srii

Senthilprakash1
Participant
0 Kudos

Hi Srini,

I have tried both the methods mentioed in below link in vain:

[http://docs.oracle.com/javase/tutorial/i18n/text/convertintro.html]

I am unable to find proper format for Chinese characters. and for UTF-8 and UTF-16 the output is same Hex value in receiver.

Also for your code.can you tell me how to return String value for output?

Thanks in advance,

Prakash.

srikanth_srinivasan3
Active Participant
0 Kudos

Hello Prakash,

I tested the piece of code myself locally before posting it. Please treat this just as a pointer. If you are attempting to print in on console, consider changing the charset of the console [for eg in Eclipse they may be a Windows default]. The document is simply dependant on the display surface. [as you mentioned about Wordpad & ALT+X] The output by my code is '中国'.

-

Srii

Senthilprakash1
Participant
0 Kudos

Hi Srijanth,

I understand it. in eclipse we need to change the console properties from windows default to utf-16 and it displays the text proper as same as in word pad.

but i am asking in PI i am not getting the output as you get in word pad or eclipse. i am not able to find the proper encoding.

Note: also for quick testing purpose in Message mapping--> do a CtrlShiftrightclick it will take you to a hidden menu...over there change the encoding format and the receiver encoding changes accordingly.

I dont know weather this hidden menu is present in PI7.1 for testing. but it is present PI7.0 which one can use for testing purpose.

Regards,

Prakash.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Prakash,

are these HEX values certain field values within XML message ?

Could you please post here the input xml and expected output XML if possible?

For the chinese character to show properly , the XML encoding has to be transformed to another value.

Now the new encoding will apply for all elements in XML thus its important to understand the input XML and the output expected by you before proposing a solution.

Regards

Anupam

Edited by: anupamsap on Feb 8, 2012 9:02 AM

Senthilprakash1
Participant
0 Kudos

All,

The issue is solved. XML is verymuch capable of handling Unicode characters and convert to Hex notation and vice versa. provided the data is sent across in required format. no UDF needed for this actually if the data coming in is in required format.

XML hexadecimal numeric character references &#xhexvalue;

Former Member
0 Kudos

Dear Senthil

It will be a good idea to use XSLT mapping if you are unable to filnd the correct functions in Java.

What you have to do here is download the Unicode for Chinease characters and use them in conversion in the XSLT mapping.

Sourabh

former_member184681
Active Contributor
0 Kudos

Hi,

You should be able to convert bytes string to UTF-16-decoded string (containing chinese characters) with a simple UDF. Use this constructor for String variable:

String result = new String(byte[] bytes, String enc);

Simply pass your hex values table to the first param and "UTF-16" as the other one. You should receive the Unicode string as a result.

Hope this helps,

Greg

Senthilprakash1
Participant
0 Kudos

Hi Grzegorz Glowacki,

I tried and its not working for me.

can you please give me the entire code. i am not able to pass the hex values. the output is erroneous.

Please do understand i am not a strong java developer.

thanks in advance.

Regards,

Prakash.

former_member184681
Active Contributor
0 Kudos

Hi Prakash,

Here is the complete code:


String result = new String(); 

try {
  byte[] bytes = new byte[input.length()/4];
    for (int i = 0; i < input.length()/4; i++) {
      byte value = Integer.valueOf(input.substring(i*4,i*4+4), 16).byteValue();
      bytes<i> = new Byte( value );
    }
    result = new String(bytes, "UTF-16");
}
catch (UnsupportedEncodingException e){}

return result;

Just remember to add one Signature Variable of type Argument, name "input" and Java Type string. I already tested it and it should be working fine.

Hope this helps,

Greg

Senthilprakash1
Participant
0 Kudos

Hi Grzegorz Glowacki,

I am sorry this is not working :(.

Sample input: 4E2D56FD -->basically this hexavalues are chinese character representation.

Output for it: ?????????

+for verification:open Wordpad-->copy the hexcode >select 4chars at a time> hit <altx> and you will get corresponding conversion value.++

String result = new String(); 
 
try {
  byte[] bytes = new byte[input.length()/4];
    for (int i = 0; i < input.length()/4; i++) {
      byte value = Integer.valueOf(input.substring(i*4,i*4+4), 16).byteValue();
      bytes<i> = new Byte( value );    *//Byte cannot be stored in byte*
    }
    result = new String(bytes, "UTF-16");
}
catch (UnsupportedEncodingException e){}
 
return result;

Also this is PI7.0 system. please do help.

thanks in advance.

Regards,

Prakash.

Edited by: senthilprakash selvaraj on Feb 2, 2012 9:38 AM