jbyteArray scanBookCoverInternal (JNIEnv * _env, jclass _class, jstring _path) { CRJNIEnv env(_env); lString16 path = env.fromJavaString(_path); CRLog::debug("scanBookCoverInternal(%s) called", LCSTR(path)); lString16 arcname, item; LVStreamRef res; jbyteArray array = NULL; LVContainerRef arc; if (!LVSplitArcName(path, arcname, item)) { // not in archive LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ); if (!stream.isNull()) { arc = LVOpenArchieve(stream); if (!arc.isNull()) { // ZIP-based format if (DetectEpubFormat(stream)) { // EPUB // extract coverpage from epub res = GetEpubCoverpage(arc); } } else { res = GetFB2Coverpage(stream); if (res.isNull()) { doc_format_t fmt; if (DetectPDBFormat(stream, fmt)) { res = GetPDBCoverpage(stream); } } } } } else { CRLog::debug("scanBookCoverInternal() : is archive, item=%s, arc=%s", LCSTR(item), LCSTR(arcname)); LVStreamRef arcstream = LVOpenFileStream(arcname.c_str(), LVOM_READ); if (!arcstream.isNull()) { arc = LVOpenArchieve(arcstream); if (!arc.isNull()) { LVStreamRef stream = arc->OpenStream(item.c_str(), LVOM_READ); if (!stream.isNull()) { CRLog::debug("scanBookCoverInternal() : archive stream opened ok, parsing"); res = GetFB2Coverpage(stream); if (res.isNull()) { doc_format_t fmt; if (DetectPDBFormat(stream, fmt)) { res = GetPDBCoverpage(stream); } } } } } } if (!res.isNull()) array = env.streamToJByteArray(res); if (array != NULL) CRLog::debug("scanBookCoverInternal() : returned cover page array"); else CRLog::debug("scanBookCoverInternal() : cover page data not found"); return array; }
/* * Class: org_coolreader_crengine_Engine * Method: scanBookCoverInternal * Signature: (Ljava/lang/String;)[B */ JNIEXPORT jbyteArray JNICALL Java_org_coolreader_crengine_Engine_scanBookCoverInternal (JNIEnv * _env, jobject _engine, jstring _path) { CRJNIEnv env(_env); lString16 path = env.fromJavaString(_path); CRLog::debug("scanBookCoverInternal(%s) called", LCSTR(path)); lString16 arcname, item; LVStreamRef res; jbyteArray array = NULL; LVContainerRef arc; if (!LVSplitArcName(path, arcname, item)) { // not in archive LVStreamRef stream = LVOpenFileStream(path.c_str(), LVOM_READ); if (!stream.isNull()) { arc = LVOpenArchieve(stream); if (!arc.isNull()) { // ZIP-based format if (DetectEpubFormat(stream)) { // EPUB // extract coverpage from epub res = GetEpubCoverpage(arc); } } else { doc_format_t fmt; if (DetectPDBFormat(stream, fmt)) { res = GetPDBCoverpage(stream); } } } } if (!res.isNull()) array = env.streamToJByteArray(res); if (array != NULL) CRLog::debug("scanBookCoverInternal() : returned cover page array"); else CRLog::debug("scanBookCoverInternal() : cover page data not found"); return array; }