JNIEXPORT jint JNICALL Java_java_util_zip_ZipFile_openZipImpl (JNIEnv * env, jobject recv, jbyteArray zipName) { VMI_ACCESS_FROM_ENV (env); PORT_ACCESS_FROM_ENV (env); I_32 retval; JCLZipFile *jclZipFile; JCLZipFileLink *zipfileHandles; jsize length; char pathCopy[HyMaxPath]; HyZipCachePool *zipCachePool; jclZipFile = jclmem_allocate_memory (env, sizeof (*jclZipFile)); if (!jclZipFile) return 3; length = (*env)->GetArrayLength (env, zipName); length = length < HyMaxPath - 1 ? length : HyMaxPath - 1; ((*env)->GetByteArrayRegion (env, zipName, 0, length, pathCopy)); pathCopy[length++] = '\0'; ioh_convertToPlatform (pathCopy); /* Open the zip file (caching will be managed automatically by zipsup) */ zipCachePool = (*VMI)->GetZipCachePool (VMI); retval = zip_openZipFile (privatePortLibrary, pathCopy, &(jclZipFile->hyZipFile), zipCachePool); if (retval) { jclmem_free_memory (env, jclZipFile); /* free on fail */ if (retval == ZIP_ERR_FILE_OPEN_ERROR) return 1; else return 2; } /* Add the zipFile we just allocated to the list of zip files -- we will * free this on UnLoad if its not already free'd. */ zipfileHandles = JCL_CACHE_GET (env, zipfile_handles); jclZipFile->last = (JCLZipFile *) zipfileHandles; jclZipFile->next = zipfileHandles->next; if (zipfileHandles->next != NULL) zipfileHandles->next->last = jclZipFile; zipfileHandles->next = jclZipFile; (*env)->SetLongField (env, recv, JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_descriptor), ((IDATA) jclZipFile)); return 0; }
char* Read_Manifest(JavaVM *vm, JNIEnv *env,const char *jar_name){ I_32 retval; #ifndef HY_ZIP_API HyZipFile zipFile; HyZipEntry zipEntry; #else VMIZipFile zipFile; VMIZipEntry zipEntry; #endif char *result; int size = 0; char errorMessage[1024]; /* Reach for the VM interface */ VMI_ACCESS_FROM_JAVAVM(vm); PORT_ACCESS_FROM_JAVAVM(vm); #ifdef HY_ZIP_API VMIZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI); #endif /* HY_ZIP_API */ /* open zip file */ #ifndef HY_ZIP_API retval = zip_openZipFile(privatePortLibrary, (char *)jar_name, &zipFile, NULL); #else /* HY_ZIP_API */ retval = zipFuncs->zip_openZipFile(VMI, (char *)jar_name, &zipFile, 0); #endif /* HY_ZIP_API */ if(retval){ sprintf(errorMessage,"failed to open file:%s, %d\n", jar_name, retval); (*env)->FatalError(env, errorMessage); return NULL; } /* get manifest entry */ #ifndef HY_ZIP_API zip_initZipEntry(privatePortLibrary, &zipEntry); retval = zip_getZipEntry(privatePortLibrary, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE); #else /* HY_ZIP_API */ zipFuncs->zip_initZipEntry(VMI, &zipEntry); retval = zipFuncs->zip_getZipEntry(VMI, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", ZIP_FLAG_READ_DATA_POINTER); #endif /* HY_ZIP_API */ if (retval) { #ifndef HY_ZIP_API zip_freeZipEntry(PORTLIB, &zipEntry); #else /* HY_ZIP_API */ zipFuncs->zip_freeZipEntry(VMI, &zipEntry); #endif /* HY_ZIP_API */ sprintf(errorMessage,"failed to get entry: %d\n", retval); (*env)->FatalError(env, errorMessage); return NULL; } /* read bytes */ size = zipEntry.uncompressedSize; result = (char *)hymem_allocate_memory(size*sizeof(char) + 1); #ifndef HY_ZIP_API retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, (unsigned char*)result, size); #else /* HY_ZIP_API */ retval = zipFuncs->zip_getZipEntryData(VMI, &zipFile, &zipEntry, (unsigned char*)result, size); #endif /* HY_ZIP_API */ if(retval){ #ifndef HY_ZIP_API zip_freeZipEntry(PORTLIB, &zipEntry); #else /* HY_ZIP_API */ zipFuncs->zip_freeZipEntry(VMI, &zipEntry); #endif /* HY_ZIP_API */ sprintf(errorMessage,"failed to get bytes from zip entry, %d\n", zipEntry.extraFieldLength); (*env)->FatalError(env, errorMessage); return NULL; } result[size] = '\0'; /* free resource */ #ifndef HY_ZIP_API zip_freeZipEntry(privatePortLibrary, &zipEntry); retval = zip_closeZipFile(privatePortLibrary, &zipFile); #else /* HY_ZIP_API */ zipFuncs->zip_freeZipEntry(VMI, &zipEntry); retval = zipFuncs->zip_closeZipFile(VMI, &zipFile); #endif /* HY_ZIP_API */ if (retval) { sprintf(errorMessage,"failed to close zip file: %s, %d\n", jar_name, retval); (*env)->FatalError(env, errorMessage); return NULL; } return result; }