From 6752505cb898c6f6b0276a31bb1b04b45350f678 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sun, 15 Aug 2010 15:06:36 +0200 Subject: [PATCH] add File.canRead()/File.canWrite() implementation --- classpath/java-io.cpp | 25 +++++++++++++++++++++++++ classpath/java/io/File.java | 12 ++++++++++++ test/FileOutput.java | 1 + 3 files changed, 38 insertions(+) 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/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;