mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
combine two jniutils methods into one
This commit is contained in:
parent
ad67f31573
commit
937bde6378
5 changed files with 43 additions and 47 deletions
|
@ -346,9 +346,11 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength,
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
JNIEnv* env = ctxt->env;
|
JNIEnv* env = ctxt->env;
|
||||||
jstring jsum = and_util_getMD5SumFor( ctxt->jniutil, ctxt->super.name );
|
jstring jsum = and_util_getMD5SumFor( ctxt->jniutil, ctxt->super.name,
|
||||||
|
NULL, 0 );
|
||||||
if ( NULL == jsum ) {
|
if ( NULL == jsum ) {
|
||||||
jsum = and_util_figureMD5Sum( ctxt->jniutil, ptr, end - ptr );
|
jsum = and_util_getMD5SumFor( ctxt->jniutil, ctxt->super.name,
|
||||||
|
ptr, end - ptr );
|
||||||
}
|
}
|
||||||
XP_UCHAR* md5Sum = getStringCopy( MPPARM(ctxt->super.mpool) env, jsum );
|
XP_UCHAR* md5Sum = getStringCopy( MPPARM(ctxt->super.mpool) env, jsum );
|
||||||
(*env)->DeleteLocalRef( env, jsum );
|
(*env)->DeleteLocalRef( env, jsum );
|
||||||
|
|
|
@ -93,28 +93,20 @@ and_util_splitFaces( JNIUtilCtxt* jniutil, const XP_U8* bytes, jsize len,
|
||||||
}
|
}
|
||||||
|
|
||||||
jstring
|
jstring
|
||||||
and_util_getMD5SumFor( JNIUtilCtxt* jniutil, const XP_UCHAR* name )
|
and_util_getMD5SumFor( JNIUtilCtxt* jniutil, const XP_UCHAR* name,
|
||||||
|
const XP_U8* bytes, jsize len )
|
||||||
{
|
{
|
||||||
JNIEnv* env = *jniutil->envp;
|
JNIEnv* env = *jniutil->envp;
|
||||||
jmethodID mid = getMethodID( env, jniutil->jjniutil, "getMD5SumFor",
|
jmethodID mid = getMethodID( env, jniutil->jjniutil, "getMD5SumFor",
|
||||||
"(Ljava/lang/String;)Ljava/lang/String;" );
|
"(Ljava/lang/String;[B)Ljava/lang/String;" );
|
||||||
jstring jname = (*env)->NewStringUTF( env, name );
|
jstring jname = (*env)->NewStringUTF( env, name );
|
||||||
|
jbyteArray jbytes = NULL == bytes? NULL
|
||||||
|
: makeByteArray( env, len, (jbyte*)bytes );
|
||||||
jstring result =
|
jstring result =
|
||||||
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jname );
|
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jname, jbytes );
|
||||||
(*env)->DeleteLocalRef( env, jname );
|
(*env)->DeleteLocalRef( env, jname );
|
||||||
|
if ( NULL != jbytes ) {
|
||||||
|
(*env)->DeleteLocalRef( env, jbytes );
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
jstring
|
|
||||||
and_util_figureMD5Sum( JNIUtilCtxt* jniutil, const XP_U8* bytes, jsize len )
|
|
||||||
{
|
|
||||||
JNIEnv* env = *jniutil->envp;
|
|
||||||
jmethodID mid = getMethodID( env, jniutil->jjniutil, "figureMD5Sum",
|
|
||||||
"([B)Ljava/lang/String;" );
|
|
||||||
jbyteArray jbytes = makeByteArray( env, len, (jbyte*)bytes );
|
|
||||||
jstring sum =
|
|
||||||
(*env)->CallObjectMethod( env, jniutil->jjniutil, mid, jbytes );
|
|
||||||
(*env)->DeleteLocalRef( env, jbytes );
|
|
||||||
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ jobject and_util_makeJBitmap( JNIUtilCtxt* jniu, int nCols, int nRows,
|
||||||
const jboolean* colors );
|
const jboolean* colors );
|
||||||
jobject and_util_splitFaces( JNIUtilCtxt* jniu, const XP_U8* bytes, int len,
|
jobject and_util_splitFaces( JNIUtilCtxt* jniu, const XP_U8* bytes, int len,
|
||||||
XP_Bool isUTF8 );
|
XP_Bool isUTF8 );
|
||||||
jstring and_util_getMD5SumFor( JNIUtilCtxt* jniutil, const XP_UCHAR* name );
|
jstring and_util_getMD5SumFor( JNIUtilCtxt* jniutil, const XP_UCHAR* name,
|
||||||
jstring and_util_figureMD5Sum( JNIUtilCtxt* jniutil, const XP_U8* bytes,
|
const XP_U8* bytes, jsize len );
|
||||||
jsize len );
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,6 +26,5 @@ public interface JNIUtils {
|
||||||
|
|
||||||
// Stuff I can't do in C....
|
// Stuff I can't do in C....
|
||||||
String[] splitFaces( byte[] chars, boolean isUTF8 );
|
String[] splitFaces( byte[] chars, boolean isUTF8 );
|
||||||
String getMD5SumFor( String dictName );
|
String getMD5SumFor( String dictName, byte[] bytes );
|
||||||
String figureMD5Sum( byte[] bytes );
|
|
||||||
}
|
}
|
|
@ -91,13 +91,13 @@ public class JNIUtilsImpl implements JNIUtils {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMD5SumFor( String dictName )
|
public String getMD5SumFor( String dictName, byte[] bytes )
|
||||||
{
|
|
||||||
return DBUtils.dictsGetMD5Sum( m_context, dictName );
|
|
||||||
}
|
|
||||||
|
|
||||||
public String figureMD5Sum( byte[] bytes )
|
|
||||||
{
|
{
|
||||||
|
DbgUtils.logf( "dictName(%H)", bytes );
|
||||||
|
String result = null;
|
||||||
|
if ( null == bytes ) {
|
||||||
|
result = DBUtils.dictsGetMD5Sum( m_context, dictName );
|
||||||
|
} else {
|
||||||
byte[] digest = null;
|
byte[] digest = null;
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
@ -115,7 +115,11 @@ public class JNIUtilsImpl implements JNIUtils {
|
||||||
} catch ( java.security.NoSuchAlgorithmException nsae ) {
|
} catch ( java.security.NoSuchAlgorithmException nsae ) {
|
||||||
DbgUtils.loge( nsae );
|
DbgUtils.loge( nsae );
|
||||||
}
|
}
|
||||||
|
result = Utils.digestToString( digest );
|
||||||
|
|
||||||
return Utils.digestToString( digest );
|
// Is this needed? Caller might be doing it anyway.
|
||||||
|
DBUtils.dictsSetMD5Sum( m_context, dictName, result );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue