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

Some converters throw ConversionBufferFullExceptions on malformed surrogates

XMLWordPrintable



      Name: akC57697 Date: 09/09/98




       The java.io.OutputStreamWriter throws CharConversionException
      for malformed surrogate pairs in non-8859_1 encodings. See the
      evaluation for bug 4167118.


      The example:
      --------------------------------8-<---------------------------
      import java.io.OutputStreamWriter;
      import java.io.ByteArrayOutputStream;
      import java.io.IOException;
      import java.io.UnsupportedEncodingException;

      class Test {
        public static void main(String[] argv) {
        
       // Tests the handling of a the high word of a character surrogate pair
       char chars[] = {'a','\uD80F','x'};

       String encodings[]={
        "8859_1","8859_2","8859_3","8859_4","8859_5","8859_6","8859_7","8859_8",
        "8859_9","Cp1250","Cp1251","Cp1252","Cp1253","Cp1254","Cp1255","Cp1256",
        "Cp1257","Cp1258","Cp437","Cp737","Cp775","Cp850","Cp852","Cp855","Cp857",
        "Cp860","Cp861","Cp862","Cp863","Cp864","Cp865","Cp866","Cp869","Cp874",
        "MacCentralEurope","MacCroatian","MacCyrillic","MacGreek","MacIceland",
        "MacRoman","MacRomania","MacThai","MacTurkish","MacUkraine" };
       OutputStreamWriter writer = null;
        
        for (int i=0; i<encodings.length; i++) {
         try {
          writer = new OutputStreamWriter(
                                    new ByteArrayOutputStream( ),encodings[i]);
         } catch( UnsupportedEncodingException e ) {
          System.out.println(encodings[i]+" "+e);
          }
                                    
         try {
          writer.write( chars ); // write chars
          System.out.println(encodings[i]+": No IOException");
         }
         catch( IOException e ) {
          System.out.println(encodings[i]+" "+e);
         }
         finally {
          try{
           writer.close();
          } catch (Exception ex) {}
         }
        }
           System.exit(0);
        }
      }

      --------------------------------8-<---------------------------
      java full version "JDK-1.2fcs-I"
      Output:
      8859_1: No IOException
      8859_2 java.io.CharConversionException: Output buffer too small
      8859_3 java.io.CharConversionException: Output buffer too small
      ...same....
         
      ======================================================================

            okutsu Masayoshi Okutsu
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: