From 447741d6ec30058e1dcbd0db090e0841eecaff18 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 28 Sep 2009 17:45:47 -0600 Subject: [PATCH] implement java.io.File.renameTo --- classpath/java-io.cpp | 21 +++++++++++++++++++++ classpath/java/io/File.java | 6 ++++++ 2 files changed, 27 insertions(+) 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/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() {