JDK-4191646 : applet hangs with java.io.CharConversionException: Output buffer too small
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6,windows_nt
  • CPU: generic,x86
  • Submitted: 1998-11-20
  • Updated: 1999-01-25
  • Resolved: 1999-01-25
Related Reports
Duplicate :  
Description
The following applet when run in appletviewer from jdk "java full version "JDK1.1.7U"" gives this stack trace:

appletviewer testUTF8Conv.html
Opening the file ./ecscmg.utf8
Creating the input stream reader
Opening the file ./utf8_ucs2_roundtrip.utf8
Creating the output stream writer
Reading UTF8 data into a buffer
java.io.CharConversionException: Output buffer too small
	at java.io.OutputStreamWriter.write(OutputStreamWriter.java)
	at java.io.OutputStreamWriter.write(OutputStreamWriter.java)
	at testUTF8Conv.init(testUTF8Conv.java:36)
	at sun.applet.AppletPanel.run(AppletPanel.java:281)
	at java.lang.Thread.run(Thread.java)

Here is the source code:

import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
import java.util.*;
import java.io.*;

public class testUTF8Conv extends Applet
{
   public void init()
   {
      String inputFileName = getParameter("InputFileName");
      String utf8OutputFileName = getParameter("UTF8OutputFileName");
      int read_result;
      char ucs_char;
        try
        {
            System.out.println("Opening the file " + inputFileName);
            FileInputStream infile = new FileInputStream(inputFileName);
            System.out.println("Creating the input stream reader");
            InputStreamReader isReader = new InputStreamReader(infile, "UTF8");

            System.out.println("Opening the file " + utf8OutputFileName);
            FileOutputStream outfile =
            new FileOutputStream(utf8OutputFileName, true);
            System.out.println("Creating the output stream writer");
            OutputStreamWriter outWriter = new OutputStreamWriter(outfile, "UTF8");

            System.out.println("Reading UTF8 data into a buffer");
            read_result = isReader.read();
            
            while (read_result != -1)
            {
                ucs_char = (char) read_result;
                //System.out.println("char:" + ucs_char);
                outWriter.write(ucs_char);
                read_result = isReader.read();
            }

            isReader.close();
            outWriter.flush();
            outWriter.close();

            System.out.println("Done!");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    
    }
}


Here is the html file to view the applet with:
testUTF8Conv.html 
<HTML>
<HEAD>
<TITLE>Testing UTF8 Converters</TITLE>
</HEAD>
<BODY>
<applet code="testUTF8Conv.class" width=900 height=350>
<param name=Language value="ja">
<param name=Territory value="JP">

<param name=Style value="Serif">
<param name=Weight value="Plain">
<param name=Size value="12">

<param name=InputFileName value="./ecscmg.utf8">
<param name=UTF8OutputFileName value="./utf8_ucs2_roundtrip.utf8">
</applet>
</BODY>
</HTML>



Comments
WORK AROUND Customer has discovered a workaround. Embed the streams in BufferedReader/BufferedWriter: import java.lang.*; import java.awt.*; import java.applet.*; import java.text.*; import java.util.*; import java.io.*; public class testUTF8Conv extends Applet { public void init() { String inputFileName = getParameter("InputFileName"); String utf8OutputFileName = getParameter("UTF8OutputFileName"); int read_result; char ucs_char; try { System.out.println("Opening the file " + inputFileName); FileInputStream infile = new FileInputStream(inputFileName); System.out.println("Creating the input stream reader"); // InputStreamReader isReader = new InputStreamReader(infile, "UTF8"); BufferedReader isReader = new BufferedReader(new InputStreamReader (infile, "UTF8")); System.out.println("Opening the file " + utf8OutputFileName); FileOutputStream outfile = new FileOutputStream(utf8OutputFileName, true); System.out.println("Creating the output stream writer"); // OutputStreamWriter outWriter = new OutputStreamWriter(outfile, "UTF8"); BufferedWriter outWriter = new BufferedWriter (new OutputStreamWriter (outfile, "UTF8")); System.out.println("Reading UTF8 data into a buffer"); read_result = isReader.read(); while (read_result != -1) { ucs_char = (char) read_result; //System.out.println("char:" + ucs_char); outWriter.write(ucs_char); read_result = isReader.read(); } isReader.close(); outWriter.flush(); outWriter.close(); System.out.println("Done!"); } catch (IOException e) { e.printStackTrace(); } } }
11-06-2004

EVALUATION This is a duplicate of 4147276, which has been fixed in both JDK 1.1.8 and JDK 1.2. I have verified that the applet described in this bug works correctly in both of those releases. -- mr@eng 1999/1/24
01-07-0190