1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#include "jnitools.h"
JNIEXPORT jlong JNICALL
Java_gl4java_utils_Tool_tmpfileCreate (
JNIEnv *env, jobject obj )
{
return (jlong) ((PointerHolder)tmpfile());
}
JNIEXPORT jboolean JNICALL
Java_gl4java_utils_Tool_tmpfileClose (
JNIEnv *env, jobject obj, jlong filed )
{
return ( fclose( (FILE *) ((PointerHolder)filed) ) == 0 ) ?
JNI_TRUE : JNI_FALSE;
}
JNIEXPORT jint JNICALL
Java_gl4java_utils_Tool_tmpfileWrite (
JNIEnv *env, jobject obj, jlong filed, jbyteArray data, int bytes)
{
jint len;
jbyte * ptr = NULL;
if(data==NULL || filed==0) return 0;
len = (*env)->GetArrayLength(env, data);
if( 0 >= bytes || bytes>len ) bytes=len;
ptr = (jbyte *) (*env)->GetPrimitiveArrayCritical(env, data, NULL);
len = (jint) fwrite ( (void *) ptr, 1, bytes,
(FILE *) ((PointerHolder)filed) );
/* NO copy back, free the memory .. */
(*env)->ReleasePrimitiveArrayCritical(env, data, ptr, JNI_ABORT);
return len;
}
JNIEXPORT jint JNICALL
Java_gl4java_utils_Tool_tmpfileRead (
JNIEnv *env, jobject obj, jlong filed, jbyteArray data, int bytes)
{
jint len;
jbyte * ptr = NULL;
if(data==NULL || filed==0) return 0;
len = (*env)->GetArrayLength(env, data);
if( 0 >= bytes || bytes>len ) bytes=len;
ptr = (jbyte *) (*env)->GetPrimitiveArrayCritical(env, data, NULL);
len = (jint) fread ( (void *) ptr, 1, bytes,
(FILE *) ((PointerHolder)filed) );
/* copy back and free the memory .. */
(*env)->ReleasePrimitiveArrayCritical(env, data, ptr, 0);
return len;
}
JNIEXPORT void JNICALL
Java_gl4java_utils_Tool_tmpfileRewind (
JNIEnv *env, jobject obj, jlong filed)
{
(void) fseek ( (FILE *) ((PointerHolder)filed), 0L, SEEK_SET );
}
|