diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 22a480cc77..9908d1b813 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -355,6 +355,27 @@ Java_java_io_File_delete(JNIEnv* e, jclass, jstring path) } } +extern "C" JNIEXPORT jboolean JNICALL +Java_java_io_File_rename(JNIEnv* e, jclass, jstring old, jstring new_) +{ + const char* oldChars = e->GetStringUTFChars(old, 0); + const char* newChars = e->GetStringUTFChars(new_, 0); + if (oldChars) { + bool v; + if (newChars) { + v = rename(oldChars, newChars) == 0; + + e->ReleaseStringUTFChars(new_, newChars); + } else { + v = false; + } + e->ReleaseStringUTFChars(old, oldChars); + return v; + } else { + return false; + } +} + extern "C" JNIEXPORT jboolean JNICALL Java_java_io_File_isDirectory(JNIEnv* e, jclass, jstring path) { diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index 8eec3cc5fc..11765dcfad 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -521,15 +521,18 @@ class Pipe { if (setBlocking(e, pipe[0], false)) { setBlocking(e, pipe[1], false); } + + open_ = true; } void dispose() { ::close(pipe[0]); ::close(pipe[1]); + open_ = false; } bool connected() { - return true; + return open_; } int reader() { @@ -542,6 +545,7 @@ class Pipe { private: int pipe[2]; + bool open_; #endif }; diff --git a/classpath/java/io/File.java b/classpath/java/io/File.java index 48c8078aed..da87db791e 100644 --- a/classpath/java/io/File.java +++ b/classpath/java/io/File.java @@ -35,6 +35,12 @@ public class File { this(parent.getPath() + FileSeparator + child); } + public static native boolean rename(String old, String new_); + + public boolean renameTo(File newName) { + return rename(path, newName.path); + } + private static native boolean isDirectory(String path); public boolean isDirectory() { diff --git a/classpath/java/nio/channels/SelectableChannel.java b/classpath/java/nio/channels/SelectableChannel.java index a49d6a292b..161fa497f2 100644 --- a/classpath/java/nio/channels/SelectableChannel.java +++ b/classpath/java/nio/channels/SelectableChannel.java @@ -16,6 +16,8 @@ import java.nio.ByteBuffer; public abstract class SelectableChannel implements Channel { private SelectionKey key; + abstract int socketFD(); + public abstract SelectableChannel configureBlocking(boolean v) throws IOException; diff --git a/classpath/java/nio/channels/ServerSocketChannel.java b/classpath/java/nio/channels/ServerSocketChannel.java index 5ddbdc0f16..178e0bbed1 100644 --- a/classpath/java/nio/channels/ServerSocketChannel.java +++ b/classpath/java/nio/channels/ServerSocketChannel.java @@ -23,6 +23,10 @@ public class ServerSocketChannel extends SelectableChannel { return new ServerSocketChannel(); } + public int socketFD() { + return channel.socketFD(); + } + public SelectableChannel configureBlocking(boolean v) throws IOException { return channel.configureBlocking(v); } diff --git a/classpath/java/nio/channels/SocketSelector.java b/classpath/java/nio/channels/SocketSelector.java index 79d01d8594..0b7c1d6b4b 100644 --- a/classpath/java/nio/channels/SocketSelector.java +++ b/classpath/java/nio/channels/SocketSelector.java @@ -72,7 +72,7 @@ class SocketSelector extends Selector { it.hasNext();) { SelectionKey key = it.next(); - SocketChannel c = (SocketChannel)key.channel(); + SelectableChannel c = key.channel(); int socket = c.socketFD(); if (c.isOpen()) { key.readyOps(0); @@ -88,7 +88,7 @@ class SocketSelector extends Selector { if (r > 0) { for (SelectionKey key : keys) { - SocketChannel c = (SocketChannel)key.channel(); + SelectableChannel c = key.channel(); int socket = c.socketFD(); int ready = natUpdateReadySet(socket, key.interestOps(), state); key.readyOps(ready);