Oooorchid commented on issue #13703:
URL: https://github.com/apache/arrow/issues/13703#issuecomment-1206098206
> Or actually @Oooorchid see #13788
>
> FWIW, I believe the immediate problem in the code is the use of a string
to transport the buffer over JNI. It should be byte[].
`ByteArrayOutputStream#toString` will attempt to decode the contents _as text_
which corrupts the content.
Thanks for your reply, your solution is perfect. I also solved this
problem few days ago. as you said using string transport over JNI will cause
some questions. I used byte[] to slove this problem finally, and there is my
example:
```
......
jclass cls = env->FindClass->("com/xxxxx");
jmethodID mid = env->GetMethodID(cls, "init", "(Ljava/lang/String;)V");
jstring arg = NewJString(name.c_str());
jobject obj = env->NewObject(cls, mid, arg);
mid = env->GetMethodID(cls, "rootToByte", "[B");
jbyteArray dataArray = (jbyteArray)env->CallObjectMethod(test, mid);
int arr_len = env->GetArrayLength(dataArray);
std::cout << "arr_len is :" << arr_len << std::endl;
jbyte* bytes = env->GetByteArrayElements(dataArray, 0);
char* ret = (char*)bytes;
env->SetByteArrayRegion(dataArray, 0, arr_len, bytes);
// Actually if thers is no _arrlen_ specified, the result will stop
when (char*)ret encounters 0
std::string result = std::string(ret, arr_len);
std::cout << "result is : " << result << std::endl;
return result;
.....
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]