Skip to Content
author's profile photo Former Member
Former Member

Re: Encode THAI Language into BASE64 Format

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Feb 02, 2012 at 09:08 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Posted on Feb 02, 2012 at 10:05 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.