Skip to content

Commit

Permalink
set default file.encoding to UTF-8 in classpath-openjdk.cpp
Browse files Browse the repository at this point in the history
This default makes more sense than ASCII, which is what it had been.
  • Loading branch information
dicej committed Apr 17, 2013
1 parent 9f8369c commit aa513c2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/classpath-openjdk.cpp
Expand Up @@ -3285,7 +3285,7 @@ jvmInitProperties(Thread* t, uintptr_t* arguments)
static_cast<Finder*> static_cast<Finder*>
(systemClassLoaderFinder(t, root(t, Machine::BootLoader)))->path()); (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 #ifdef ARCH_x86_32
local::setProperty(t, method, *properties, "os.arch", "x86"); local::setProperty(t, method, *properties, "os.arch", "x86");
#elif defined ARCH_x86_64 #elif defined ARCH_x86_64
Expand Down
47 changes: 47 additions & 0 deletions test/Strings.java
Expand Up @@ -7,6 +7,31 @@ private static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(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) { private static boolean arraysEqual(Object[] a, Object[] b) {
if (a.length != b.length) { if (a.length != b.length) {
return false; return false;
Expand Down Expand Up @@ -146,5 +171,27 @@ public static void main(String[] args) throws Exception {
"I", "grape", "nuts", "foobar", "I", "grape", "nuts", "foobar",
new Object() { public String toString() { return "you"; } }) new Object() { public String toString() { return "you"; } })
.equals("I enjoy grape nuts. do you? you do?")); .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.