cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Encode THAI Language into BASE64 Format

Former Member
0 Kudos

Hi Guru's,

Have a requirement to encode particular IDOC text fields which are in THAI language to BASE64 format . We are able to encode the same for english but not able to do the same for Thai language so can any one help with the coding to create custom UDF which can convert.

Regards

Sathish Kumar K.C

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member184681
Active Contributor
0 Kudos

Hi,

It looks like you complicated it a little bit Why don't you use a dedicated library for that purpose? See an example here:

http://www.rgagnon.com/javadetails/java-0598.html

Simply use the Apache Commons Codec example. Of course you need to download the library first and import it to PI, as an Imported Archive.

Hope this helps,

Greg

former_member184681
Active Contributor
0 Kudos

Hi Sathish,

Please provide your code for conversion of English text so that we could help you modify to work for Thai as well. In general, this should be very similar in both cases.

Greg

Former Member
0 Kudos

Hi ,

Please find below my code...

public class Base64a {

// Mapping table from 6-bit nibbles to Base64 characters.

private static char[] map1 = new char[64];

static {

int i=0;

for (char c='A'; c<='Z'; c+) map1[i+] = c;

for (char c='a'; c<='z'; c+) map1[i+] = c;

for (char c='0'; c<='9'; c+) map1[i+] = c;

map1[i+] = ''; map1[i++] = '/'; }

// Mapping table from Base64 characters to 6-bit nibbles.

private static byte[] map2 = new byte[128];

static {

for (int i=0; i<map2.length; i++) map2<i> = -1;

for (int i=0; i<64; i++) map2[map1<i>] = (byte)i; }

/**

  • Encodes a string into Base64 format.

  • No blanks or line breaks are inserted.

  • @param s a String to be encoded.

  • @return A String with the Base64 encoded data.

*/

public static String encode (String s) {

return new String(encode(s.getBytes())); }

/**

  • Encodes a byte array into Base64 format.

  • No blanks or line breaks are inserted.

  • @param in an array containing the data bytes to be encoded.

  • @return A character array with the Base64 encoded data.

*/

public static char[] encode (byte[] in) {

int iLen = in.length;

int oDataLen = (iLen*4+2)/3; // output length without padding

int oLen = ((iLen+2)/3)*4; // output length including padding

char[] out = new char[oLen];

int ip = 0;

int op = 0;

while (ip < iLen) {

int i0 = in[ip++] & 0xff;

int i1 = ip < iLen ? in[ip++] & 0xff : 0;

int i2 = ip < iLen ? in[ip++] & 0xff : 0;

int o0 = i0 >>> 2;

int o1 = ((i0 & 3) << 4) | (i1 >>> 4);

int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);

int o3 = i2 & 0x3F;

out[op++] = map1[o0];

out[op++] = map1[o1];

out[op] = op < oDataLen ? map1[o2] : '='; op++;

out[op] = op < oDataLen ? map1[o3] : '='; op++; }

return out; }

Regards

Sathish Kumar