> The need here is to ...
Callback from C to Java is fine for read(). But seek() might be an issue since for true random access we need to be able to seek forward and backwards from
1. start of the stream
2. current pos of the stream
3. end of the stream
After taking a deep dive into the minizip code and implementing some POC code I am not sure how a seek() callback from C to java might be implemented in way that can be leveraged from existing minizip parser code. Any suggestions ?
Just to give an idea, here is a some sample code for read() that I implemented.
// including zlib & minizip libraries
// including java library
//defining read() and seek() IO APIs
uLong ZCALLBACK fread_file_func
( voidpf opaque, voidpf stream, void* buf, uLong size)
JNIEnv *env = (JNIEnv *) opaque;
jobject javaStream = (jobject) stream;
jclass dataInputStream = (*env)->GetObjectClass(env, stream);
jmethodID MID_read = (*env)->GetMethodID(env, dataInputStream, "read", "([BII)I");
if(MID_read == NULL)
printf("\nfread_file_func(): read() method not found");
jbyteArray byteArray = (*env)->NewByteArray(env, size);
bytesRead = (*env)->CallIntMethod(env, javaStream, MID_read, byteArray, 0, size);
(*env)->GetByteArrayRegion(env, byteArray, 0, bytesRead, buf);
printf("\nNumber of bytes read: %u\n", bytesRead );
// the native function exposed to Java, declared as a static method
// dataStream is of type java.io.DataInputStream.
// zipClass is of type ZipInputformat
JNIEXPORT void JNICALL Java_ZipInputFormat_display
(JNIEnv *env, jclass zipClass, jobject dataStream)
unsigned char * buf = (unsigned char *) malloc( sizeof (unsigned char) * 1024 * 64);
fread_file_func(env, dataStream, buf, 64*1024);