mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Fix getContent() for 5.0
This commit is contained in:
parent
0604bcc92e
commit
5337592002
28
kiwix.c
28
kiwix.c
@ -10,6 +10,9 @@
|
|||||||
#include "unicode/putil.h"
|
#include "unicode/putil.h"
|
||||||
#include <kiwix/reader.h>
|
#include <kiwix/reader.h>
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "kiwix", __VA_ARGS__)
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
kiwix::Reader *reader = NULL;
|
kiwix::Reader *reader = NULL;
|
||||||
|
|
||||||
@ -157,10 +160,10 @@ JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getContent(JNIE
|
|||||||
setStringObjValue("", mimeTypeObj, env);
|
setStringObjValue("", mimeTypeObj, env);
|
||||||
setIntObjValue(0, sizeObj, env);
|
setIntObjValue(0, sizeObj, env);
|
||||||
jbyteArray data = env->NewByteArray(0);
|
jbyteArray data = env->NewByteArray(0);
|
||||||
|
bool isOK = false;
|
||||||
|
|
||||||
/* Retrieve the content */
|
/* Retrieve the content */
|
||||||
if (reader != NULL) {
|
if (reader != NULL) {
|
||||||
|
|
||||||
std::string cUrl = jni2c(url, env);
|
std::string cUrl = jni2c(url, env);
|
||||||
std::string cData;
|
std::string cData;
|
||||||
std::string cMimeType;
|
std::string cMimeType;
|
||||||
@ -168,19 +171,26 @@ JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getContent(JNIE
|
|||||||
|
|
||||||
pthread_mutex_lock(&readerLock);
|
pthread_mutex_lock(&readerLock);
|
||||||
try {
|
try {
|
||||||
if (reader->getContentByUrl(cUrl, cData, cSize, cMimeType)) {
|
isOK = reader->getContentByUrl(cUrl, cData, cSize, cMimeType);
|
||||||
data = env->NewByteArray(cSize);
|
|
||||||
jbyte *dataPointer = env->GetByteArrayElements(data, 0);
|
|
||||||
memcpy(dataPointer, cData.c_str(), cSize);
|
|
||||||
|
|
||||||
setStringObjValue(cMimeType, mimeTypeObj, env);
|
|
||||||
setIntObjValue(cSize, sizeObj, env);
|
|
||||||
}
|
|
||||||
} catch (exception &e) {
|
} catch (exception &e) {
|
||||||
|
LOGI(e.what());
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&readerLock);
|
pthread_mutex_unlock(&readerLock);
|
||||||
|
|
||||||
|
if (isOK) {
|
||||||
|
if (cSize > 142) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "JNI values for " << cUrl << ":" << (int)(cData[142]) << "," << (int)(cData[143]) << "," << (int)(cData[144]);
|
||||||
|
LOGI(ss.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
data = env->NewByteArray(cSize);
|
||||||
|
env->SetByteArrayRegion(data, 0, cSize, reinterpret_cast<const jbyte*>(cData.c_str()));
|
||||||
|
|
||||||
|
setStringObjValue(cMimeType, mimeTypeObj, env);
|
||||||
|
setIntObjValue(cSize, sizeObj, env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user