arpadboda commented on issue #489: MINIFICPP-740: Add ability to run NiFi processors from Java and Python URL: https://github.com/apache/nifi-minifi-cpp/pull/489#issuecomment-468223437 @phrocker: I don't like the fact that JNI API doesn't provide RAII wrapper from UTF string handling, so I quickly sratched one: ``` class JNIUTFString { public: JNIUTFString(JNIEnv * env, jstring jstr) { _env = env; _jstr = jstr; _cstr = _env->GetStringUTFChars(_jstr, NULL); } ~JNIUTFString() { _env->ReleaseStringUTFChars(_jstr, _cstr); } operator std::string() const { return _cstr; } const char * c_str() const { return _cstr; } friend std::ostream& operator<<(std::ostream& os, const JNIUTFString& jutfstr); private: JNIEnv * _env; const char * _cstr; jstring _jstr; }; std::ostream& operator<<(std::ostream& os, const JNIUTFString& jutfstr) { os << jutfstr.c_str(); return os; } ``` This can be used as an std::string, but you don't have to deal with conversion, releasing, etc, usage is simple: ``` JNIUTFString jutf(env, jstr); std::set<std::string> test_set; test_set.insert(jutf); std::cout << jutf <<std::endl; std::cout << jutf.c_str() << std::endl; ``` Feel free to add if you like it.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
