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>