diff --git a/classpath/java-lang.cpp b/classpath/java-lang.cpp index 0f3b838d9b..c5cd630fbf 100644 --- a/classpath/java-lang.cpp +++ b/classpath/java-lang.cpp @@ -281,6 +281,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid) return exitCode; } +extern "C" JNIEXPORT void JNICALL +Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) { + TerminateProcess(reinterpret_cast(pid), 1); +} + Locale getLocale() { const char* lang = ""; const char* reg = ""; @@ -468,6 +473,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv*, jclass, jlong pid, jlong) return exitCode; } +extern "C" JNIEXPORT void JNICALL +Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) { + kill((pid_t)pid, SIGTERM); +} + Locale getLocale() { Locale fallback; diff --git a/classpath/java/io/BufferedReader.java b/classpath/java/io/BufferedReader.java index 236a086b80..2618dfdbd6 100644 --- a/classpath/java/io/BufferedReader.java +++ b/classpath/java/io/BufferedReader.java @@ -46,8 +46,7 @@ public class BufferedReader extends Reader { sb.append(buffer, position, i - position); position = i + 1; if(i+1 < limit && buffer[i+1] == '\n') { - position = i + 1; - return sb.toString(); + position = i + 2; } return sb.toString(); } else if (buffer[i] == '\n') { diff --git a/classpath/java/io/InputStream.java b/classpath/java/io/InputStream.java index a225432044..8e74c2db8d 100644 --- a/classpath/java/io/InputStream.java +++ b/classpath/java/io/InputStream.java @@ -56,7 +56,7 @@ public abstract class InputStream { } public void reset() throws IOException { - // ignore + throw new IOException("mark/reset not supported"); } public boolean markSupported() { diff --git a/classpath/java/io/RandomAccessFile.java b/classpath/java/io/RandomAccessFile.java index a2f40bce76..cc3c41e757 100644 --- a/classpath/java/io/RandomAccessFile.java +++ b/classpath/java/io/RandomAccessFile.java @@ -12,16 +12,21 @@ package java.io; public class RandomAccessFile { private long peer; - private long length; + private File file; private long position = 0; - + private long length; + public RandomAccessFile(String name, String mode) throws FileNotFoundException { if (! mode.equals("r")) throw new IllegalArgumentException(); + file = new File(name); + open(); + } + private void open() throws FileNotFoundException { long[] result = new long[2]; - open(name, result); + open(file.getPath(), result); peer = result[0]; length = result[1]; } @@ -29,7 +34,15 @@ public class RandomAccessFile { private static native void open(String name, long[] result) throws FileNotFoundException; + private void refresh() throws IOException { + if (file.length() != length) { + close(); + open(); + } + } + public long length() throws IOException { + refresh(); return length; } @@ -38,7 +51,7 @@ public class RandomAccessFile { } public void seek(long position) throws IOException { - if (position < 0 || position > length) throw new IOException(); + if (position < 0 || position > length()) throw new IOException(); this.position = position; } @@ -50,12 +63,16 @@ public class RandomAccessFile { if (length == 0) return; - if (position + length > this.length) throw new EOFException(); + if (position + length > this.length) { + if (position + length > length()) throw new EOFException(); + } if (offset < 0 || offset + length > buffer.length) throw new ArrayIndexOutOfBoundsException(); copy(peer, position, buffer, offset, length); + + position += length; } private static native void copy(long peer, long position, byte[] buffer, diff --git a/classpath/java/lang/Runtime.java b/classpath/java/lang/Runtime.java index a24f850bf3..bf80507deb 100644 --- a/classpath/java/lang/Runtime.java +++ b/classpath/java/lang/Runtime.java @@ -122,6 +122,8 @@ public class Runtime { private static native void load(String name, boolean mapName); + private static native void kill(long pid); + public native void gc(); public native void exit(int code); @@ -147,7 +149,7 @@ public class Runtime { } public void destroy() { - throw new RuntimeException("not implemented"); + kill(pid); } public InputStream getInputStream() { diff --git a/classpath/java/nio/Buffer.java b/classpath/java/nio/Buffer.java index 3de26da72f..c93c11f347 100644 --- a/classpath/java/nio/Buffer.java +++ b/classpath/java/nio/Buffer.java @@ -15,45 +15,50 @@ public abstract class Buffer { protected int position; protected int limit; - public int limit() { + public final int limit() { return limit; } - public int remaining() { + public final int remaining() { return limit-position; } - public int position() { + public final int position() { return position; } - public int capacity() { + public final int capacity() { return capacity; } - public Buffer limit(int newLimit) { + public final Buffer limit(int newLimit) { limit = newLimit; return this; } - public Buffer position(int newPosition) { + public final Buffer position(int newPosition) { position = newPosition; return this; } - public boolean hasRemaining() { + public final boolean hasRemaining() { return remaining() > 0; } - public Buffer clear() { + public final Buffer clear() { position = 0; limit = capacity; return this; } - public Buffer flip() { + public final Buffer flip() { limit = position; position = 0; return this; } + + public final Buffer rewind() { + position = 0; + return this; + } } diff --git a/test/Processes.java b/test/Processes.java new file mode 100644 index 0000000000..372513f0c1 --- /dev/null +++ b/test/Processes.java @@ -0,0 +1,31 @@ +import java.io.IOException; + +public class Processes { + public static void main(String[] args) { + long start = System.currentTimeMillis(); + try { + final Process p = Runtime.getRuntime().exec("sleep 10"); + new Thread() { + public void run() { + try { + Thread.sleep(100); + } catch(InterruptedException e) { + // ignore + } + p.destroy(); + } + }.start(); + try { + p.waitFor(); + } catch(InterruptedException e) { + // ignore + } + long stop = System.currentTimeMillis(); + if(stop - start > 5000) { + throw new RuntimeException("test failed; we didn't kill the process..."); + } + } catch(IOException e) { + throw new RuntimeException(e); + } + } +}