mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-22 07:28:16 +01:00
factor common code into function
This commit is contained in:
parent
81d3f7d15f
commit
598a154693
3 changed files with 16 additions and 15 deletions
|
@ -238,6 +238,17 @@ makeByteArray( JNIEnv *env, int siz, const jbyte* vals )
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jbyteArray
|
||||||
|
streamToBArray( JNIEnv *env, XWStreamCtxt* stream )
|
||||||
|
{
|
||||||
|
int nBytes = stream_getSize( stream );
|
||||||
|
jbyteArray result = (*env)->NewByteArray( env, nBytes );
|
||||||
|
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
||||||
|
stream_getBytes( stream, jelems, nBytes );
|
||||||
|
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
|
setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
|
||||||
const jboolean* vals )
|
const jboolean* vals )
|
||||||
|
|
|
@ -57,6 +57,7 @@ void setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
|
||||||
|
|
||||||
jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals );
|
jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals );
|
||||||
jstring streamToJString( JNIEnv* env, XWStreamCtxt* stream );
|
jstring streamToJString( JNIEnv* env, XWStreamCtxt* stream );
|
||||||
|
jbyteArray streamToBArray( JNIEnv *env, XWStreamCtxt* stream );
|
||||||
|
|
||||||
/* Note: jmethodID can be cached. Should not look up more than once. */
|
/* Note: jmethodID can be cached. Should not look up more than once. */
|
||||||
jmethodID getMethodID( JNIEnv* env, jobject obj, const char* proc,
|
jmethodID getMethodID( JNIEnv* env, jobject obj, const char* proc,
|
||||||
|
|
|
@ -214,11 +214,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_gi_1to_1stream
|
||||||
game_saveToStream( NULL, gi, stream, 0 );
|
game_saveToStream( NULL, gi, stream, 0 );
|
||||||
destroyGI( MPPARM(mpool) &gi );
|
destroyGI( MPPARM(mpool) &gi );
|
||||||
|
|
||||||
int nBytes = stream_getSize( stream );
|
result = streamToBArray( env, stream );
|
||||||
result = (*env)->NewByteArray( env, nBytes );
|
|
||||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
|
||||||
stream_getBytes( stream, jelems, nBytes );
|
|
||||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
|
|
||||||
vtmgr_destroy( MPPARM(mpool) vtMgr );
|
vtmgr_destroy( MPPARM(mpool) vtMgr );
|
||||||
|
@ -545,13 +541,9 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream
|
||||||
destroyGI( MPPARM(mpool) &gi );
|
destroyGI( MPPARM(mpool) &gi );
|
||||||
}
|
}
|
||||||
|
|
||||||
int nBytes = stream_getSize( stream );
|
state->lastSavedSize = stream_getSize( stream );
|
||||||
result = (*env)->NewByteArray( env, nBytes );
|
result = streamToBArray( env, stream );
|
||||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
|
||||||
stream_getBytes( stream, jelems, nBytes );
|
|
||||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
|
||||||
stream_destroy( stream );
|
stream_destroy( stream );
|
||||||
state->lastSavedSize = nBytes;
|
|
||||||
|
|
||||||
XWJNI_END();
|
XWJNI_END();
|
||||||
return result;
|
return result;
|
||||||
|
@ -1636,10 +1628,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_base64Decode
|
||||||
XP_U8 out[inlen];
|
XP_U8 out[inlen];
|
||||||
XP_U16 outlen = VSIZE(out);
|
XP_U16 outlen = VSIZE(out);
|
||||||
if ( smsToBin( out, &outlen, instr, inlen ) ) {
|
if ( smsToBin( out, &outlen, instr, inlen ) ) {
|
||||||
result = (*env)->NewByteArray( env, outlen );
|
result = makeByteArray( env, outlen, (jbyte*)out );
|
||||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
|
||||||
XP_MEMCPY( jelems, out, outlen );
|
|
||||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
|
||||||
} else {
|
} else {
|
||||||
XP_ASSERT(0);
|
XP_ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue