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

ISO2022CN_CNS & ISO2022CN_GB charset not supported in BufferedReader.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.2, 1.2.0
    • core-libs
    • generic, x86, sparc
    • generic, solaris_8, windows_95

      Name: rm29839 Date: 05/21/98


      ISO2022CN_CNS & ISO2022CN_GB is not supported in
      the BufferedReader class.
      It is Ok for BufferedWriter.

      That means that you could not read back what you write
      using the above 2 charset encoding.

      Below is the ISO2022 file uses to generate a File
      with the specified encoding.

      import java.io.*;
      public class ISO2022 {
          public static void main (String args[])
          {
              String m_encoding="ISO2022CN_GB";
              String output_text="key in some chinese text here «f¿Â¨pªü";
              File m_file = new File ("output.txt");
              
              try {
                          FileOutputStream oStream = new FileOutputStream(m_file);
                          OutputStreamWriter encode_writer = new OutputStreamWriter( oStream, m_encoding);
                          BufferedWriter b_writer = new BufferedWriter(encode_writer);
                          b_writer.write (output_text, 0, output_text.length());
                          b_writer.flush();
                      }
              catch (IOException ie)
              {
                  System.out.println ("Encoding not supported!!!!!");
               }
          } //main
      } // iso2022

      Below is the ISOreader file which I use to read
      back what I encode in "output.txt". But it throws an Exception.

      mport java.io.*;
      public class ISOreader{
          public static void main (String args[])
          {
              String m_encoding="ISO2022CN_CNS";
                File m_file = new File ("output.txt");
              FileInputStream inStream ;
              InputStreamReader encode_reader;
              BufferedReader b_reader ;
              char [] cbuf =new char[100];
              String readtext;
              try {
                           inStream = new FileInputStream(m_file);
                           encode_reader = new InputStreamReader( inStream, m_encoding);

                           b_reader = new BufferedReader(encode_reader);
                           if(b_reader .ready())
                           {
      // readtext=b_reader.readLine(cbuf,0,50 );
                                 b_reader.read(cbuf,0,50 );
                                 readtext=new String(cbuf);
                              System.out.println( "the file contains : "+readtext);
                           }
                              if (b_reader !=null)
                                  b_reader.close();
                              if (encode_reader !=null)
                                   encode_reader.close();
                              if (inStream != null)
                                  inStream.close();
                      }
              catch (IOException ie)
              {
                  System.out.println ("Encoding not supported!!!!!");
               }
              
             
          } //main
      } // iso2022
      (Review ID: 28804)
      ======================================================================

            ilittlesunw Ian Little (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: