Microsoft KB Archive/280062

= FIX: java.io.OutputStreamWriter Class Incorrectly Throws Exception =

Article ID: 280062

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine

-



This article was previously published under Q280062



SYMPTOMS
When the java.io.OutputStreamWriter class uses multiple-byte character encoding systems, it may incorrectly throw a CharConversionException exception with an &quot;OutputBuffer too small&quot; detail string.



CAUSE
This problem occurs if previous operations nearly fill up the byte array conversion buffer (with only 1, 2, or 3 bytes left in the buffer) and the first character of a new incoming conversion operation is too large to fit in the buffer's remaining space.



RESOLUTION
To resolve this problem on computers that are running Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows Millennium Edition (Me), Microsoft Windows NT, and Microsoft Windows 2000, download and install the latest build of the Microsoft VM.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
  Create a new file named Test.java, and paste the following code: import java.util.*; import java.io.*;

public class Test {   public static void main(String[] args) throws IOException {       ByteArrayOutputStream bos; OutputStreamWriter osw; byte[] array; bos = new ByteArrayOutputStream; osw = new OutputStreamWriter(bos, &quot;UTF8&quot;);

try {           for(int count = 1; count < 3000; ++count) osw.write('\u3042'); // Hiragana

osw.close; array = bos.toByteArray;

System.out.println( &quot;Number of UTF8 bytes written &quot;+ array.length ); }       catch( CharConversionException ex) {           System.out.println(ex.getMessage); }   } }                     At a command prompt, type the following command to compile the source file:

jvc Test.java

 At a command prompt, type the following command to run the class file:

jview Test.class

 Because the CharConversionException exception is incorrectly thrown, you receive the following message:

Output buffer too small



<div class="references_section">