diff options
author | Sven Gothel <[email protected]> | 2020-07-04 01:18:04 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-04 01:18:04 +0200 |
commit | 91bc030606bb9a2c7a89b64d4028c2160221dfe0 (patch) | |
tree | f7d7be7fe1054e4386f76cdd637ac8d619728062 /java | |
parent | 57bb75c7322c1572a0add0416ebb61b7fd5e868d (diff) |
Extract dfa_utf8_decode.[cpp/hpp] added to libtinyb.so, i.e. used for both native libs commonly exposed in Java via BluetoothUtils.cxx JNI
Diffstat (limited to 'java')
-rw-r--r-- | java/jni/BluetoothUtils.cxx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/java/jni/BluetoothUtils.cxx b/java/jni/BluetoothUtils.cxx index 83e71dd..b05ec66 100644 --- a/java/jni/BluetoothUtils.cxx +++ b/java/jni/BluetoothUtils.cxx @@ -30,6 +30,11 @@ #include <time.h> +#include "JNIMem.hpp" +#include "helper_base.hpp" + +#include "direct_bt/dfa_utf8_decode.hpp" + static const int64_t NanoPerMilli = 1000000L; static const int64_t MilliPerOne = 1000L; @@ -51,3 +56,26 @@ jlong Java_org_tinyb_BluetoothUtils_getCurrentMilliseconds(JNIEnv *env, jclass c return (jlong)res; } +jstring Java_org_tinyb_BluetoothUtils_decodeUTF8String(JNIEnv *env, jclass clazz, jbyteArray jbuffer, jint offset, jint size) { + (void)clazz; + + const int buffer_size = env->GetArrayLength(jbuffer); + if( 0 == buffer_size ) { + return env->NewStringUTF(""); + } + if( buffer_size < offset+size ) { + std::string msg("buffer.length "+std::to_string(buffer_size)+ + " < offset "+std::to_string(offset)+ + " + size "+std::to_string(size)); + throw std::invalid_argument(msg.c_str()); + } + + JNICriticalArray<uint8_t> criticalArray(env); // RAII - release + uint8_t * buffer_ptr = criticalArray.get(jbuffer, criticalArray.Mode::NO_UPDATE_AND_RELEASE); + if( NULL == buffer_ptr ) { + throw std::invalid_argument("GetPrimitiveArrayCritical(byte array) is null"); + } + std::string sres = dfa_utf8_decode(buffer_ptr+offset, size); + + return from_string_to_jstring(env, sres); +} |