System properties
Michael Hall
mik3hall at gmail.com
Sun May 27 15:46:53 PDT 2012
> I mean if run jvm in C or POSIX locale, the file.encoding is set to US-ASCII by Oracle 7u4/7u6, which
> is expected.
>
> -Sherman
OK, since locale has been indicated as the determiner.
Consider….
public class LocaleTester {
public static void main(String[] args) {
System.out.println("java.version="+System.getProperty("java.version"));
System.out.println("file.encoding="+System.getProperty("file.encoding"));
System.out.println(rtexec(new String[] { "locale" }));
}
private static String rtexec(String[] args) {
try {
StringBuilder execout = new StringBuilder();
Process proc = Runtime.getRuntime().exec(args);
proc.waitFor();
java.io.InputStream inout = proc.getInputStream();
java.io.InputStream inerr = proc.getErrorStream();
byte []buffer = new byte[256];
while (true) {
int stderrLen = inerr.read(buffer, 0, buffer.length);
if (stderrLen > 0) {
execout.append(new String(buffer,0,stderrLen));
}
int stdoutLen = inout.read(buffer, 0, buffer.length);
if (stdoutLen > 0) {
execout.append(new String(buffer,0,stdoutLen));
}
if (stderrLen < 0 && stdoutLen < 0)
break;
}
return execout.toString();
}
catch(Throwable tossed) { tossed.printStackTrace(); }
return "-";
}
}
Run Terminal 1..7 (Should be an Oracle build at the moment)
/usr/libexec/java_home -v 1.7 --exec java LocaleTester
java.version=1.7.0_04
file.encoding=UTF-8
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
Run Terminal 1.6
/usr/libexec/java_home -v 1.6 --exec java LocaleTester
java.version=1.6.0_31
file.encoding=MacRoman
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
Run using built-in functionality from my application (Again for this should be a Oracle 1.7 build)
set java.version
java.version=1.7.0_04
set file.encoding
file.encoding=US-ASCII
exec locale
LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
Apple 1.6 never seems to give UTF-8 contrary to what Andrew said. It is always MacRoman. Either he was not accurate in what he said or is changing the property to UTF-8 somewhere that he isn't aware of it.
1.7 gives UTF-8 or US-ASCII depending on how it is run. From Terminal command line you get UTF-8.
From an application for some reason you get the C/POSIX locale and get US-ASCII for the encoding.
According to Xueming Shen who I'm guessing has some Java responsibility involving these things, all of this is correct for the given locale's except as I recall he agreed the prior MacRoman might be problematic. To which Andrew Thompson's other points may of course be valid and worth being addressed.
I still have no problems or issues but a little curiosity as to why command line java and application java are run differently involving different locale's and ending up with different properties?
More information about the macosx-port-dev
mailing list