diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 134045bdd2..05b54da2c9 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -377,6 +377,31 @@ Java_java_io_File_delete(JNIEnv* e, jclass, jstring path) } } +extern "C" JNIEXPORT jboolean JNICALL +Java_java_io_File_canRead(JNIEnv* e, jclass, jstring path) +{ + string_t chars = getChars(e, path); + if (chars) { + int r = access(chars, R_OK); + releaseChars(e, path, chars); + return (r == 0); + } + return false; +} + +extern "C" JNIEXPORT jboolean JNICALL +Java_java_io_File_canWrite(JNIEnv* e, jclass, jstring path) +{ + string_t chars = getChars(e, path); + if (chars) { + int r = access(chars, W_OK); + releaseChars(e, path, chars); + return (r == 0); + } + return false; +} + + extern "C" JNIEXPORT jboolean JNICALL Java_java_io_File_rename(JNIEnv* e, jclass, jstring old, jstring new_) { diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index c3fa42932f..86ef77c6a3 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -60,7 +60,19 @@ public class File { public boolean isFile() { return isFile(path); } + + private static native boolean canRead(String path); + + public boolean canRead() { + return canRead(path); + } + private static native boolean canWrite(String path); + + public boolean canWrite() { + return canWrite(path); + } + public String getName() { int index = path.lastIndexOf(FileSeparator); if (index >= 0) { diff --git a/classpath/java/io/ObjectInputStream.java b/classpath/java/io/ObjectInputStream.java index 001a192a73..8447e10efa 100644 --- a/classpath/java/io/ObjectInputStream.java +++ b/classpath/java/io/ObjectInputStream.java @@ -79,6 +79,10 @@ public class ObjectInputStream extends InputStream { read('d'); return readDoubleToken(); } + + public void defaultReadObject() throws IOException { + throw new UnsupportedOperationException(); + } private void skipSpace() throws IOException { int c; diff --git a/classpath/java/io/ObjectOutputStream.java b/classpath/java/io/ObjectOutputStream.java index 42d080f676..90743a5b32 100644 --- a/classpath/java/io/ObjectOutputStream.java +++ b/classpath/java/io/ObjectOutputStream.java @@ -82,6 +82,10 @@ public class ObjectOutputStream extends OutputStream { out.print(v); } + public void defaultWriteObject() throws IOException { + throw new UnsupportedOperationException(); + } + private void writeObject(Object o, IdentityHashMap map, int nextId) throws IOException diff --git a/classpath/java/lang/SecurityManager.java b/classpath/java/lang/SecurityManager.java new file mode 100644 index 0000000000..0b522c5bfb --- /dev/null +++ b/classpath/java/lang/SecurityManager.java @@ -0,0 +1,30 @@ +/* Copyright (c) 2010, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.lang; + +import java.security.AccessController; +import java.security.Permission; +import java.security.SecurityPermission; + +public class SecurityManager { + + public SecurityManager() { + } + + public void checkPermission(Permission perm) { + AccessController.checkPermission(perm); + } + + public void checkSecurityAccess(String target) { + checkPermission(new SecurityPermission(target)); + } + +} diff --git a/classpath/java/lang/String.java b/classpath/java/lang/String.java index 143c60fd72..9362822b65 100644 --- a/classpath/java/lang/String.java +++ b/classpath/java/lang/String.java @@ -236,19 +236,31 @@ public final class String } public String toLowerCase() { - char[] b = new char[length]; - for (int i = 0; i < length; ++i) { - b[i] = Character.toLowerCase(charAt(i)); + for (int j = 0; j < length; ++j) { + char ch = charAt(j); + if (Character.toLowerCase(ch) != ch) { + char[] b = new char[length]; + for (int i = 0; i < length; ++i) { + b[i] = Character.toLowerCase(charAt(i)); + } + return new String(b, 0, length, false); + } } - return new String(b, 0, length, false); + return this; } public String toUpperCase() { - char[] b = new char[length]; - for (int i = 0; i < length; ++i) { - b[i] = Character.toUpperCase(charAt(i)); + for (int j = 0; j < length; ++j) { + char ch = charAt(j); + if (Character.toUpperCase(ch) != ch) { + char[] b = new char[length]; + for (int i = 0; i < length; ++i) { + b[i] = Character.toUpperCase(charAt(i)); + } + return new String(b, 0, length, false); + } } - return new String(b, 0, length, false); + return this; } public int indexOf(int c) { @@ -581,11 +593,19 @@ public final class String } public String toUpperCase(Locale locale) { - throw new UnsupportedOperationException(); + if (locale == Locale.ENGLISH) { + return toUpperCase(); + } else { + throw new UnsupportedOperationException("toUpperCase("+locale+')'); + } } public String toLowerCase(Locale locale) { - throw new UnsupportedOperationException(); + if (locale == Locale.ENGLISH) { + return toLowerCase(); + } else { + throw new UnsupportedOperationException("toLowerCase("+locale+')'); + } } public static String format(Locale locale, String format, Object ... args) { diff --git a/classpath/java/lang/System.java b/classpath/java/lang/System.java index ac3ee11b3a..c060493e7c 100644 --- a/classpath/java/lang/System.java +++ b/classpath/java/lang/System.java @@ -22,6 +22,7 @@ import java.util.Properties; public abstract class System { private static Property properties; + private static SecurityManager securityManager; // static { // loadLibrary("natives"); // } @@ -118,6 +119,14 @@ public abstract class System { public static void exit(int code) { Runtime.getRuntime().exit(code); } + + public static SecurityManager getSecurityManager() { + return securityManager; + } + + public static void setSecurityManager(SecurityManager securityManager) { + System.securityManager = securityManager; + } private static class Property { public final String name; diff --git a/classpath/java/security/AccessController.java b/classpath/java/security/AccessController.java index 804dfe70a7..b219e450ae 100644 --- a/classpath/java/security/AccessController.java +++ b/classpath/java/security/AccessController.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, Avian Contributors +/* Copyright (c) 2008, 2010 Avian Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided @@ -21,5 +21,9 @@ public class AccessController { public static Object doPrivileged (PrivilegedAction action) { return action.run(); } + + public static void checkPermission(Permission perm) throws AccessControlException { + + } } diff --git a/classpath/java/security/AllPermission.java b/classpath/java/security/AllPermission.java index 6bc99d53e8..b35004f609 100644 --- a/classpath/java/security/AllPermission.java +++ b/classpath/java/security/AllPermission.java @@ -10,4 +10,10 @@ package java.security; -public class AllPermission extends Permission { } +public class AllPermission extends Permission { + public AllPermission() { + super(""); + } + + +} diff --git a/classpath/java/security/BasicPermission.java b/classpath/java/security/BasicPermission.java new file mode 100644 index 0000000000..756e70139d --- /dev/null +++ b/classpath/java/security/BasicPermission.java @@ -0,0 +1,19 @@ +/* Copyright (c) 2010, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.security; + +public class BasicPermission extends Permission { + + public BasicPermission(String name) { + super(name); + } + +} diff --git a/classpath/java/security/Permission.java b/classpath/java/security/Permission.java index bc6c438e18..528795a127 100644 --- a/classpath/java/security/Permission.java +++ b/classpath/java/security/Permission.java @@ -11,6 +11,22 @@ package java.security; public abstract class Permission { + + protected String name; + + public Permission(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return this.getClass().getSimpleName() + '['+name+']'; + } + public PermissionCollection newPermissionCollection() { return null; } diff --git a/classpath/java/security/SecurityPermission.java b/classpath/java/security/SecurityPermission.java new file mode 100644 index 0000000000..22660f6111 --- /dev/null +++ b/classpath/java/security/SecurityPermission.java @@ -0,0 +1,19 @@ +/* Copyright (c) 2010, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.security; + +public class SecurityPermission extends BasicPermission { + + public SecurityPermission(String name) { + super(name); + } + +} diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index 8206988d90..cf05144d7d 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -148,5 +148,11 @@ public class Arrays { array[i] = value; } } + + public static void fill(T[] array, T value) { + for (int i=0;i (c.iterator()); } + public static Comparator reverseOrder(Comparator cmp) { + return new ReverseComparator(cmp); + } + static class IteratorEnumeration implements Enumeration { private final Iterator it; @@ -379,4 +384,20 @@ public class Collections { it.remove(); } } + + private static final class ReverseComparator implements Comparator { + + Comparator cmp; + + public ReverseComparator(Comparator cmp) { + this.cmp = cmp; + } + + @Override + public int compare(T o1, T o2) { + return - cmp.compare(o1, o2); + } + + } + } diff --git a/classpath/java/util/ConcurrentModificationException.java b/classpath/java/util/ConcurrentModificationException.java new file mode 100644 index 0000000000..28fe2bf7ee --- /dev/null +++ b/classpath/java/util/ConcurrentModificationException.java @@ -0,0 +1,47 @@ +/* Copyright (c) 2010, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +package java.util; + +/** + * @author zsombor + * + */ +public class ConcurrentModificationException extends RuntimeException { + + /** + * @param message + * @param cause + */ + public ConcurrentModificationException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param message + */ + public ConcurrentModificationException(String message) { + super(message); + } + + /** + * @param cause + */ + public ConcurrentModificationException(Throwable cause) { + super(cause); + } + + /** + * + */ + public ConcurrentModificationException() { + } + +} diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index c0a8a2474a..0f00f920b2 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -269,8 +269,10 @@ public class HashMap implements Map { return value; } - public void setValue(V value) { + public V setValue(V value) { + V old = this.value; this.value = value; + return old; } public HashMap.Cell next() { diff --git a/classpath/java/util/Map.java b/classpath/java/util/Map.java index 5b58bbb4f9..cd20bbc809 100644 --- a/classpath/java/util/Map.java +++ b/classpath/java/util/Map.java @@ -40,6 +40,6 @@ public interface Map { public V getValue(); - public void setValue(V value); + public V setValue(V value); } } diff --git a/classpath/java/util/Properties.java b/classpath/java/util/Properties.java index 749869823b..1ff67dcf16 100644 --- a/classpath/java/util/Properties.java +++ b/classpath/java/util/Properties.java @@ -14,10 +14,15 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.IOException; +import java.io.Reader; public class Properties extends Hashtable { public void load(InputStream in) throws IOException { - new Parser().parse(in, this); + new InputStreamParser(in).parse(this); + } + + public void load(Reader reader) throws IOException { + new ReaderParser(reader).parse(this); } public void store(OutputStream out, String comment) throws IOException { @@ -53,7 +58,7 @@ public class Properties extends Hashtable { return keys(); } - private static class Parser { + private abstract static class Parser { private StringBuilder key = null; private StringBuilder value = null; private StringBuilder current = null; @@ -79,13 +84,15 @@ public class Properties extends Hashtable { key = value = current = null; } - private void parse(InputStream in, Map map) + abstract int readCharacter() throws IOException; + + void parse(Map map) throws IOException { boolean escaped = false; int c; - while ((c = in.read()) != -1) { + while ((c = readCharacter()) != -1) { if (c == '\\') { if (escaped) { escaped = false; @@ -98,7 +105,7 @@ public class Properties extends Hashtable { case '#': case '!': if (key == null) { - while ((c = in.read()) != -1 && c != '\n'); + while ((c = readCharacter()) != -1 && c != '\n'); } else { append(c); } @@ -153,4 +160,32 @@ public class Properties extends Hashtable { finishLine(map); } } + + static class InputStreamParser extends Parser { + InputStream in; + + + public InputStreamParser(InputStream in) { + this.in = in; + } + + @Override + int readCharacter() throws IOException { + return in.read(); + } + } + + static class ReaderParser extends Parser { + Reader in; + + public ReaderParser(Reader in) { + this.in = in; + } + + @Override + int readCharacter() throws IOException { + return in.read(); + } + } + } diff --git a/classpath/java/util/TreeMap.java b/classpath/java/util/TreeMap.java index 686e9ffda3..b3141422cd 100644 --- a/classpath/java/util/TreeMap.java +++ b/classpath/java/util/TreeMap.java @@ -112,9 +112,12 @@ public class TreeMap implements Map { return value; } - public void setValue(V value) { + public V setValue(V value) { + V old = this.value; this.value = value; + return old; } + } private class KeySet implements Set { diff --git a/classpath/java/util/WeakHashMap.java b/classpath/java/util/WeakHashMap.java index d8fdbc7968..81365b9816 100644 --- a/classpath/java/util/WeakHashMap.java +++ b/classpath/java/util/WeakHashMap.java @@ -114,8 +114,10 @@ public class WeakHashMap implements Map { return value; } - public void setValue(V value) { + public V setValue(V value) { + V old = this.value; this.value = value; + return old; } public HashMap.Cell next() { diff --git a/test/FileOutput.java b/test/FileOutput.java index db4273f650..29df89da9a 100644 --- a/test/FileOutput.java +++ b/test/FileOutput.java @@ -1,3 +1,4 @@ +import java.io.File; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.File;