JDK-4140796 : ISO2022CN_CNS & ISO2022CN_GB charset not supported in BufferedReader.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 1.1.2,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_8,windows_95
  • CPU: generic,x86,sparc
  • Submitted: 1998-05-21
  • Updated: 2003-11-21
  • Resolved: 2003-11-21
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
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)
======================================================================

Comments
SUGGESTED FIX [xueming.shen@Japan 1999-06-02] *** /tmp/geta5094 Wed Jun 2 16:49:23 1999 --- CharToByteISO2022.java Wed Jun 2 15:55:34 1999 *************** *** 30,36 **** private final byte P3 = (byte)0xA3; private final byte MSB = (byte)0x80; ! protected final byte maximumDesignatorLength = 3; protected String SODesignator, SS2Designator = null, --- 30,36 ---- private final byte P3 = (byte)0xA3; private final byte MSB = (byte)0x80; ! protected final byte maximumDesignatorLength = 4; protected String SODesignator, SS2Designator = null, *** /tmp/geta4921 Wed Jun 2 16:48:32 1999 --- ByteToCharISO2022.java Wed Jun 2 16:48:21 1999 *************** *** 117,126 **** --- 117,128 ---- break; case SS2Flag: tmpIndex = curSS2Des; + tmpByte = new byte[]{(byte)0x8e, (byte)0xa2, byte1,byte2}; tmpConverter = (ByteToCharConverter [])SS2Converter; break; case SS3Flag: tmpIndex = curSS3Des; + tmpByte = new byte[]{(byte)0x8e, (byte)0xa3, byte1,byte2}; tmpConverter = (ByteToCharConverter [])SS3Converter; break; } *************** *** 128,134 **** for(i = 0; i < tmpConverter.length; i++) { if(tmpIndex == i) { try { ! tmpConverter[i].convert(tmpByte, 0, 2, tmpChar, 0, 1); } catch (Exception e) {} return tmpChar[0]; } --- 130,136 ---- for(i = 0; i < tmpConverter.length; i++) { if(tmpIndex == i) { try { ! tmpConverter[i].convert(tmpByte, 0, tmpByte.length, tmpChar, 0, 1); } catch (Exception e) {} return tmpChar[0]; }
11-06-2004

EVALUATION For reading, ByteToCharISO2022CN can support both ISO2022_CN and ISO2022_GB because the character sets can be recognized by the escape sequences. This is the reason why ISO2022CN_* converters are not provided for reading. masayoshi.okutsu@Eng 1998-08-05 I'm closing this bug because the plan was not to provide those readers. If symmetric naming is required, please reopen this bug or file a separate request. masayoshi.okutsu@Eng 1999-04-12 Well, our documentation about supported encodings doesn't distinguish between input and output. And it lists all three names. I think we need to resolve this, one way or another. norbert.lindenberg@Eng 1999-04-15 Actually there are at least two bugs in our iso2022 btc/ctb implementations which cause iso2022 converters totally not work for CNS plane 2 & 3 with SS2 and SS3 (we should support plane 3,4,5,6,7 too, but it may need rewrite the whole implementation, I think we may leave it after kestrel), see bug#4247378 xueming.shen@Japan 1999-06-02 A fix for this bug will be revisited for the next feature release, Tiger ###@###.### 2003-01-20 Fix was already provided by means of bugIDs, 4779029 & 4737614 Should be verifiable in b28 1.5.0 (and probably earlier builds too) ###@###.### 2003-11-21
20-01-2003

WORK AROUND Use the ISO2022CN converter for reading. masayoshi.okutsu@Eng 1998-08-05
05-08-1998