Hi,

I believe this is a bug that was introduced somewhere between 1.1.5 and
1.1.7, but I'm not sure what the behavior really should be.  I'm not
sure if it's linux-specific, but I don't currently have another machine
to test on.  Basically it looks like some system properties are being
ignored after they're changed.

I want to change the file.encoding system property within a program
instead of setting it with -Dfile.encoding= on invocation, so that the
default encoding for various classes can be changed dynamically and
constructors don't need a string encoding parameter.

Here's a bit of code:

----------
class EncodingTest {
    public static void main(String[] argv) throws IOException {
        Properties p = System.getProperties();
        p.put("user.language", "ja");
        p.put("file.encoding", "EUCJIS");
        System.setProperties(p);        
        System.out.println("user.language: "+
                           System.getProperty("user.language"));
        System.out.println("file.encoding: "+
                           System.getProperty("file.encoding"));
        System.out.println("OutputStreamWriter encoding: " + new 
            OutputStreamWriter(System.out).getEncoding());
        System.out.println("FileWriter encoding: " + new 
            FileWriter(new File("ttt")).getEncoding());
    }
}
----------

On 1.1.7 i386 and alpha:

user.language=ja
file.encoding=EUCJIS
OutputStreamWriter encoding: ISO8859_1
FileWriter encoding: ISO8859_1

with -Dfile.encoding=SJIS

user.language=ja
file.encoding=EUCJIS
OutputStreamWriter encoding: SJIS
FileWriter encoding: SJIS

However, with 1.1.5 on i386 and alpha both encodings for
OuputStreamWriter and FileWriter are reported as EUCJIS, which is what I
expect.

I'm having a hard time finding documentation on this sort of stuff, but
I assume that the 1.1.5 behavior is correct.  I also assume that
changing the property only affects the creation of new objects that
check the file.encoding property.  Is that right?  So I'm assuming that
System.out has not changed encoding (actually, I believe a problem with
foreign character sets is why PrintStream is deprecated?), but the new
OutputStreamWriter's encoding *is* affected by the property.  Extra
question: if that's the case, how do you use System.out to print
non-8859-1 strings without converting them to a byte array or using a
wrapper (I'm thinking about what would be involved to convert an english
program to a multi-byte one)?

Anyone have pointers to more in-depth docs on this?

thanks,
-Wes.

Reply via email to