mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #328 from kiwix/java_article_size
[JAVA] Add a method to get the size of an article.
This commit is contained in:
commit
90ba27fbab
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
|
#include <exception>
|
||||||
#include "org_kiwix_kiwixlib_JNIKiwixReader.h"
|
#include "org_kiwix_kiwixlib_JNIKiwixReader.h"
|
||||||
|
|
||||||
#include "tools/base64.h"
|
#include "tools/base64.h"
|
||||||
|
@ -305,6 +306,22 @@ JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getContentPa
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL
|
||||||
|
Java_org_kiwix_kiwixlib_JNIKiwixReader_getArticleSize(
|
||||||
|
JNIEnv* env, jobject obj, jstring url)
|
||||||
|
{
|
||||||
|
std::string cUrl = jni2c(url, env);
|
||||||
|
try {
|
||||||
|
auto entry = READER->getEntryFromEncodedPath(cUrl);
|
||||||
|
entry = entry.getFinalEntry();
|
||||||
|
return c2jni(entry.getSize(), env);
|
||||||
|
} catch(std::exception& e) {
|
||||||
|
LOG("Unable to get size for url : %s", cUrl.c_str());
|
||||||
|
LOG(e.what());
|
||||||
|
}
|
||||||
|
return c2jni(0, env);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_org_kiwix_kiwixlib_JNIKiwixReader_getDirectAccessInformation(
|
Java_org_kiwix_kiwixlib_JNIKiwixReader_getDirectAccessInformation(
|
||||||
JNIEnv* env, jobject obj, jstring url)
|
JNIEnv* env, jobject obj, jstring url)
|
||||||
|
|
|
@ -82,6 +82,16 @@ public class JNIKiwixReader
|
||||||
int len,
|
int len,
|
||||||
JNIKiwixInt size);
|
JNIKiwixInt size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get the size of an article.
|
||||||
|
*
|
||||||
|
* @param url The url of the article.
|
||||||
|
* @return The size of the final (redirections are resolved) article (in byte).
|
||||||
|
* Return 0 if the article is not found.
|
||||||
|
*/
|
||||||
|
public native long getArticleSize(String url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getDirectAccessInformation.
|
* getDirectAccessInformation.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue