mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +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;
|
||||
}
|
||||
|
||||
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
|
||||
setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
|
||||
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 );
|
||||
jstring streamToJString( JNIEnv* env, XWStreamCtxt* stream );
|
||||
jbyteArray streamToBArray( JNIEnv *env, XWStreamCtxt* stream );
|
||||
|
||||
/* Note: jmethodID can be cached. Should not look up more than once. */
|
||||
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 );
|
||||
destroyGI( MPPARM(mpool) &gi );
|
||||
|
||||
int nBytes = stream_getSize( stream );
|
||||
result = (*env)->NewByteArray( env, nBytes );
|
||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
||||
stream_getBytes( stream, jelems, nBytes );
|
||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
||||
result = streamToBArray( env, stream );
|
||||
stream_destroy( stream );
|
||||
|
||||
vtmgr_destroy( MPPARM(mpool) vtMgr );
|
||||
|
@ -545,13 +541,9 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1saveToStream
|
|||
destroyGI( MPPARM(mpool) &gi );
|
||||
}
|
||||
|
||||
int nBytes = stream_getSize( stream );
|
||||
result = (*env)->NewByteArray( env, nBytes );
|
||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
||||
stream_getBytes( stream, jelems, nBytes );
|
||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
||||
state->lastSavedSize = stream_getSize( stream );
|
||||
result = streamToBArray( env, stream );
|
||||
stream_destroy( stream );
|
||||
state->lastSavedSize = nBytes;
|
||||
|
||||
XWJNI_END();
|
||||
return result;
|
||||
|
@ -1636,10 +1628,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_base64Decode
|
|||
XP_U8 out[inlen];
|
||||
XP_U16 outlen = VSIZE(out);
|
||||
if ( smsToBin( out, &outlen, instr, inlen ) ) {
|
||||
result = (*env)->NewByteArray( env, outlen );
|
||||
jbyte* jelems = (*env)->GetByteArrayElements( env, result, NULL );
|
||||
XP_MEMCPY( jelems, out, outlen );
|
||||
(*env)->ReleaseByteArrayElements( env, result, jelems, 0 );
|
||||
result = makeByteArray( env, outlen, (jbyte*)out );
|
||||
} else {
|
||||
XP_ASSERT(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue