Permalink
Browse files

set default file.encoding to UTF-8 in classpath-openjdk.cpp

This default makes more sense than ASCII, which is what it had been.
  • Loading branch information...
1 parent 9f8369c commit aa513c2c1dcde7fb9e329f6a7a491da544d73e42 @dicej dicej committed Apr 17, 2013
Showing with 48 additions and 1 deletion.
  1. +1 −1 src/classpath-openjdk.cpp
  2. +47 −0 test/Strings.java
View
2 src/classpath-openjdk.cpp
@@ -3285,7 +3285,7 @@ jvmInitProperties(Thread* t, uintptr_t* arguments)
static_cast<Finder*>
(systemClassLoaderFinder(t, root(t, Machine::BootLoader)))->path());
- local::setProperty(t, method, *properties, "file.encoding", "ASCII");
+ local::setProperty(t, method, *properties, "file.encoding", "UTF-8");
#ifdef ARCH_x86_32
local::setProperty(t, method, *properties, "os.arch", "x86");
#elif defined ARCH_x86_64
View
47 test/Strings.java
@@ -7,6 +7,31 @@ private static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}
+ private static boolean arraysEqual(byte[] a, byte[] b) {
+ if (a.length != b.length) {
+ return false;
+ }
+
+ for (int i = 0; i < a.length; ++i) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static byte[] append(byte[] a, byte[] b) {
+ byte[] c = new byte[a.length + b.length];
+ for (int i = 0; i < a.length; ++i) {
+ c[i] = a[i];
+ }
+ for (int i = 0; i < b.length; ++i) {
+ c[i + a.length] = b[i];
+ }
+ return c;
+ }
+
private static boolean arraysEqual(Object[] a, Object[] b) {
if (a.length != b.length) {
return false;
@@ -146,5 +171,27 @@ public static void main(String[] args) throws Exception {
"I", "grape", "nuts", "foobar",
new Object() { public String toString() { return "you"; } })
.equals("I enjoy grape nuts. do you? you do?"));
+
+ { java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
+ java.io.PrintStream pout = new java.io.PrintStream(bout);
+ String s = "I ♥ grape nuts";
+ System.out.println(s);
+ pout.println(s);
+
+ expect
+ (arraysEqual
+ (bout.toByteArray(),
+ (s + System.getProperty("line.separator")).getBytes()));
+
+ // note that this effectively asserts that the VM's default
+ // charset is UTF-8. If we want to make this test more
+ // portable, we should specify the charset explicitly.
+ expect
+ (arraysEqual
+ (bout.toByteArray(), append
+ (new byte[] { 73, 32, -30, -103, -91, 32, 103, 114, 97, 112, 101,
+ 32, 110, 117, 116, 115 },
+ System.getProperty("line.separator").getBytes())));
+ }
}
}

0 comments on commit aa513c2

Please sign in to comment.