-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
5.0
-
None
-
x86
-
solaris
When we write character to file and then read it back from file using supported ISO2022JP encoding we get different chars, e.g
"Written char: ''(code: 15), read char: '!)'(code: 65533)"
Below is a small java class that demonstrates the problem:
import java.io.*;
public class ISO2022JP_Test {
public static final int TOP_VALUE = 10000;
public static int wrongCounter = 0;
public static void main(String[] args) {
System.out.println("Encoding being used: " + System.getProperty("file.encoding"));
char[] chars = new char[TOP_VALUE];
for (int i = 0; i < TOP_VALUE; i++) {
testFileWriteRead((char)i);
}
System.out.println(wrongCounter + " characters don't match of " + TOP_VALUE);
}
private static void testFileWriteRead(char writeChar) {
try {
File tmp = File.createTempFile("read_write", "test");
FileWriter fw = new FileWriter(tmp);
fw.write(writeChar);
fw.close();
FileReader fr = new FileReader(tmp);
char readChar = (char)fr.read();
if (readChar != writeChar) {
System.out.println("Written char: '" + writeChar + "'(code: " + (int)writeChar + " ), read char: '" + readChar + "'(code: " + (int)readChar + ")");
wrongCounter++;
}
fr.close();
tmp.delete();
} catch (IOException ex) {
ex.printStackTrace(System.out);
}
}
}
If we run this program with option "-Dfile.encoding=ISO2022JP" we get big list of unmatching characters with following summary: 9641 characters don't match of 10000
"Written char: ''(code: 15), read char: '!)'(code: 65533)"
Below is a small java class that demonstrates the problem:
import java.io.*;
public class ISO2022JP_Test {
public static final int TOP_VALUE = 10000;
public static int wrongCounter = 0;
public static void main(String[] args) {
System.out.println("Encoding being used: " + System.getProperty("file.encoding"));
char[] chars = new char[TOP_VALUE];
for (int i = 0; i < TOP_VALUE; i++) {
testFileWriteRead((char)i);
}
System.out.println(wrongCounter + " characters don't match of " + TOP_VALUE);
}
private static void testFileWriteRead(char writeChar) {
try {
File tmp = File.createTempFile("read_write", "test");
FileWriter fw = new FileWriter(tmp);
fw.write(writeChar);
fw.close();
FileReader fr = new FileReader(tmp);
char readChar = (char)fr.read();
if (readChar != writeChar) {
System.out.println("Written char: '" + writeChar + "'(code: " + (int)writeChar + " ), read char: '" + readChar + "'(code: " + (int)readChar + ")");
wrongCounter++;
}
fr.close();
tmp.delete();
} catch (IOException ex) {
ex.printStackTrace(System.out);
}
}
}
If we run this program with option "-Dfile.encoding=ISO2022JP" we get big list of unmatching characters with following summary: 9641 characters don't match of 10000