Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4756251

string.getBytes(Cp420) does not work the same as getBytes(Cp1256)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P5 P5
    • None
    • 1.4.0
    • core-libs

      Name: nt126004 Date: 10/01/2002


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
      Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      The result of getBytes works for Cp1256 (Windows Arabic)
      but does not work for Cp420 (IBM Arabic).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Program source:





      2. use javac to compile the program then run it.
      3. the result is:
      (Cp1256)
      defaultBytes[0] = 0x3f
      defaultBytes[1] = 0x3f
      defaultBytes[2] = 0x3f
      defaultBytes[3] = 0xc7
      defaultBytes[4] = 0xc8
      defaultBytes[5] = 0xc9
      defaultBytes[6] = 0xca
      defaultBytes[7] = 0xcb
      defaultBytes[8] = 0xcc
      defaultBytes[9] = 0xcd
      defaultBytes[10] = 0xce
      defaultBytes[11] = 0xcf
      defaultBytes[12] = 0xd0
      defaultBytes[13] = 0xd1
      defaultBytes[14] = 0xd2
      defaultBytes[15] = 0xd3
      defaultBytes[16] = 0xd4
      defaultBytes[17] = 0xd5
      defaultBytes[18] = 0xd6
      defaultBytes[19] = 0xd8
      defaultBytes[20] = 0xd9
      defaultBytes[21] = 0xda
      defaultBytes[22] = 0xdb
      defaultBytes[23] = 0xdd
      defaultBytes[24] = 0xde
      defaultBytes[25] = 0xdf
      defaultBytes[26] = 0xe1
      defaultBytes[27] = 0xe3
      defaultBytes[28] = 0xe4
      defaultBytes[29] = 0xe5
      defaultBytes[30] = 0xec
      defaultBytes[31] = 0xec
      defaultBytes[32] = 0xed

      (Cp420)
      convertedBytes[0] = 0xea
      convertedBytes[1] = 0xeb
      convertedBytes[2] = 0xed
      convertedBytes[3] = 0x3f
      convertedBytes[4] = 0x3f
      convertedBytes[5] = 0x3f
      convertedBytes[6] = 0x3f
      convertedBytes[7] = 0x3f
      convertedBytes[8] = 0x3f
      convertedBytes[9] = 0x3f
      convertedBytes[10] = 0x3f
      convertedBytes[11] = 0x3f
      convertedBytes[12] = 0x3f
      convertedBytes[13] = 0x3f
      convertedBytes[14] = 0x3f
      convertedBytes[15] = 0x3f
      convertedBytes[16] = 0x3f
      convertedBytes[17] = 0x3f
      convertedBytes[18] = 0x3f
      convertedBytes[19] = 0x3f
      convertedBytes[20] = 0x3f
      convertedBytes[21] = 0x3f
      convertedBytes[22] = 0x3f
      convertedBytes[23] = 0x3f
      convertedBytes[24] = 0x3f
      convertedBytes[25] = 0x3f
      convertedBytes[26] = 0x3f
      convertedBytes[27] = 0x3f
      convertedBytes[28] = 0x3f
      convertedBytes[29] = 0x3f
      convertedBytes[30] = 0x3f
      convertedBytes[31] = 0x3f
      convertedBytes[32] = 0x3f



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ------- BEGIN SOURCE --------
      /**
       * Insert the type's description here.
       * Creation date: (2002/9/17 ?U?? 10:06:00)
       * @author: Administrator
       */
      import java.lang.*;
      import java.io.*;

      public class ConversionTest {
      /**
       * ConversionTest constructor comment.
       */

      public ConversionTest() {
      super();
      }

         static public String byteToHex(byte b) {
            // Returns hex String representation of byte b
            char hexDigit[] = {
               '0', '1', '2', '3', '4', '5', '6', '7',
               '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
            };
            char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit
      [b & 0x0f] };
            return new String(array);
         }

         static public String charToHex(char c) {
            // Returns hex String representation of char c
            byte hi = (byte) (c >>> 8);
            byte lo = (byte) (c & 0xff);
            return byteToHex(hi) + byteToHex(lo);
         }

         static public void printBytes(byte[] array, String name)
      {
            for (int k = 0; k < array.length; k++) {
               System.out.println(name + "[" + k + "] = " + "0x" +
                  byteToHex(array[k]));
            }
         }

      /**
       * Starts the application.
       * @param args an array of command-line arguments
       */
      public static void main(java.lang.String[] args) {
      // Insert code to start the application here.
      //Unicode testing 2 - input from Window 2000 IME
      java.lang.String unicode = "\u0661\u0662\u0663\u0627
      \u0628\u0629\u062A\u062B\u062C\u062D\u062E\u062F\u0630\u0631
      \u0632\u0633\u0634\u0635\u0636\u0637\u0638\u0639\u063A\u0641
      \u0642\u0643\u0644\u0645\u0646\u0647\u0649\u0649\u064A";

                    File outputFile = new File("out.txt");

      try
      {
                       FileWriter out = new FileWriter(outputFile);
                       out.write(unicode);
                       out.write(" ");
      System.out.println(unicode);

                       // convert unicode to non-unicode byte array in Cp1256 format
                       byte[] defaultBytes = unicode.getBytes ("Cp1256");

                       // convert unicode to non-unicode byte array in Cp420 format
      byte[] convertedBytes= unicode.getBytes("Cp420");


                       // ConversionTest.printBytes(defaultBytes, "defaultBytes");
                       ConversionTest.printBytes(convertedBytes, "convertedBytes");

                       // make a string object with Cp420 encoding
      String str = new String(convertedBytes,"Cp420");

      System.out.println(str);
      out.write(str);
                       out.close();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }
      }
      -------- END SOURCE ---------
      (Review ID: 164904)
      ======================================================================

            ilittlesunw Ian Little (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: