diff options
author | Max Kellermann <max@duempel.org> | 2014-03-01 20:53:39 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-03-01 20:53:39 +0100 |
commit | 5268f55344229f70e3565f63671eb582eaff733f (patch) | |
tree | f16f39a0847ea56b03db8892c3368251e4f2b3bf /src/java | |
parent | e44c9a000d477ba9fd24bd77ab4b529001dd3bde (diff) | |
download | mpd-5268f55344229f70e3565f63671eb582eaff733f.tar.gz mpd-5268f55344229f70e3565f63671eb582eaff733f.tar.xz mpd-5268f55344229f70e3565f63671eb582eaff733f.zip |
java/File: add method ToAbsolutePath() returning AllocatedPath
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/File.cxx | 27 | ||||
-rw-r--r-- | src/java/File.hxx | 14 |
2 files changed, 39 insertions, 2 deletions
diff --git a/src/java/File.cxx b/src/java/File.cxx index 03e3defdf..8e9599dfc 100644 --- a/src/java/File.cxx +++ b/src/java/File.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 Max Kellermann <max@duempel.org> + * Copyright (C) 2010-2014 Max Kellermann <max@duempel.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,13 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "File.hxx" #include "Class.hxx" +#include "String.hxx" +#include "Object.hxx" +#include "fs/AllocatedPath.hxx" +#include "fs/Limits.hxx" jmethodID Java::File::getAbsolutePath_method; @@ -40,3 +45,23 @@ Java::File::Initialise(JNIEnv *env) getAbsolutePath_method = env->GetMethodID(cls, "getAbsolutePath", "()Ljava/lang/String;"); } + +AllocatedPath +Java::File::ToAbsolutePath(JNIEnv *env, jobject _file) +{ + assert(env != nullptr); + assert(_file != nullptr); + + LocalObject file(env, _file); + + const jstring path = getAbsolutePath(env, file); + if (path == nullptr) { + env->ExceptionClear(); + return AllocatedPath::Null(); + } + + Java::String path2(env, path); + char buffer[MPD_PATH_MAX]; + path2.CopyTo(env, buffer, sizeof(buffer)); + return AllocatedPath::FromUTF8(buffer); +} diff --git a/src/java/File.hxx b/src/java/File.hxx index 57af6199c..3636fc7c6 100644 --- a/src/java/File.hxx +++ b/src/java/File.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012 Max Kellermann <max@duempel.org> + * Copyright (C) 2010-2014 Max Kellermann <max@duempel.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,6 +34,8 @@ #include <jni.h> +class AllocatedPath; + namespace Java { /** * Wrapper for a java.io.File object. @@ -42,12 +44,22 @@ namespace Java { static jmethodID getAbsolutePath_method; public: + gcc_nonnull_all static void Initialise(JNIEnv *env); + gcc_nonnull_all static jstring getAbsolutePath(JNIEnv *env, jobject file) { return (jstring)env->CallObjectMethod(file, getAbsolutePath_method); } + + /** + * Invoke File.getAbsolutePath() and release the + * specified File reference. + */ + gcc_pure gcc_nonnull_all + static AllocatedPath ToAbsolutePath(JNIEnv *env, + jobject file); }; } |