-
Bug
-
Resolution: Fixed
-
P3
-
1.1.7
-
b02
-
sparc
-
solaris_2.6
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2027924 | 1.3.0 | Koushi Takahashi | P3 | Resolved | Fixed | kestrel |
JDK-2027923 | 1.2.2_002 | Koushi Takahashi | P3 | Resolved | Fixed | b02 |
Name: clC74495 Date: 07/05/99
OutputStreamWriter outputs illegal characters with JIS(iso-2022-jp) encoding when
given such string that has a different type of character at the point of 8K bytes, which
is the boundary of its inner buffer size. (Test program is jislength.java).
The reason is supported to be that CharToByteConverter.convert unexpectedly
abandons the necessary escape sequence which is used to convert character types
as it throws away filled buffer.
On further inquiry, CharToByteISO202JP was found to be containing unsuitable codes
as follows:
(Around line 200 of the source)
> if (currentMode != JISX0208_1983) {
> outputByte[0] = (byte)0x1b;
> outputByte[1] = (byte)0x24;
> outputByte[2] = (byte)0x42;
> outputByte[3] = (byte)(index >> 8);
> outputByte[4] = (byte)(index & 0xff);
> outputSize = 5;
> currentMode = JISX0208_1983;
> } else {
...
> // Is there room in the output buffer?
> if (byteOff + outputSize > outEnd)
> throw new ConversionBufferFullException();
Note when Exception is thrown in the lower part, the escape sequence is not written,
however, currentMode = JISX0208_1983 is already done in the upper part.
The currentMode should be set after it is clear no Exception is thrown in that part.
To work around, we have some sidesteps:
1. Fix sun.io.charToByteISO2022JP and replace for the old.
2. Make some improvement on OutputStreamWriter.
The very improvable procedure is in the method public void write(char[] int, int) like that:
if ((nextByte >= nBytes) || bufferFull) {
// out.write(bb, 0, nextByte); // old code
// nextByte = 0; // old code
flushBuffer(); // new code
bufferFlushed = true;
}
Even though it is rather redundant, we can get legal JIS data.
jislength.java
---------------------------------------------------
import java.io.Writer ;
import java.io.OutputStreamWriter ;
import java.io.IOException ;
class jislength {
public static void
main(String args[])
throws Exception
{
testOutput(new OutputStreamWriter(System.out, "iso-2022-jp")) ;
}
static void
testOutput(final Writer out)
throws IOException
{
try {
for(int i = 0 ; i < 8 * 1024 - 2 ; i++){
out.write(' ') ;
}
out.write("a=83=9F\n") ;
} finally {
out.flush() ;
}
}
}
(Review ID: 85071)
======================================================================
- backported by
-
JDK-2027923 OutputStreamWriter outputs illegal characters with JIS at the poi=
-
- Resolved
-
-
JDK-2027924 OutputStreamWriter outputs illegal characters with JIS at the poi=
-
- Resolved
-