Exemple #1
0
JNIEXPORT jlong JNICALL
Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
                                        jint mode, jlong lastModified,
                                        jboolean usemmap)
{
    const char *path = JNU_GetStringPlatformChars(env, name, 0);
    char *msg = 0;
    jlong result = 0;
    int flag = 0;
    jzfile *zip = 0;

    if (mode & OPEN_READ) flag |= O_RDONLY;
    if (mode & OPEN_DELETE) flag |= JVM_O_DELETE;

    if (path != 0) {
        zip = ZIP_Get_From_Cache(path, &msg, lastModified);
        if (zip == 0 && msg == 0) {
            ZFILE zfd = 0;
#ifdef WIN32
            zfd = winFileHandleOpen(env, name, flag);
            if (zfd == -1) {
                /* Exception already pending. */
                goto finally;
            }
#else
            zfd = JVM_Open(path, flag, 0);
            if (zfd < 0) {
                throwFileNotFoundException(env, name);
                goto finally;
            }
#endif
            zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
        }

        if (zip != 0) {
            result = ptr_to_jlong(zip);
        } else if (msg != 0) {
            ThrowZipException(env, msg);
            free(msg);
        } else if (errno == ENOMEM) {
            JNU_ThrowOutOfMemoryError(env, 0);
        } else {
            ThrowZipException(env, "error in opening zip file");
        }
finally:
        JNU_ReleaseStringPlatformChars(env, name, path);
    }
    return result;
}
    WITH_PLATFORM_STRING(env, path, ps) {
        FD fd;

#ifdef __linux__
        /* Remove trailing slashes, since the kernel won't */
        char *p = (char *)ps + strlen(ps) - 1;
        while ((p > ps) && (*p == '/'))
            *p-- = '\0';
#endif
        fd = JVM_Open(ps, flags, 0666);
        if (fd >= 0) {
            SET_FD(this, fd, fid);
        } else {
            throwFileNotFoundException(env, path);
        }
    } END_PLATFORM_STRING(env, ps);
Exemple #3
0
JNIEXPORT jboolean JNICALL Java_org_clearsilver_HDF__1readFile(
    JNIEnv *env, jobject objClass, jint hdf_obj_ptr, jstring j_filename,
    jboolean use_cb) {
  HDF *hdf = (HDF *)hdf_obj_ptr;
  NEOERR *err;
  const char *filename;
  jboolean retval;
  FILELOAD_INFO fl_info;

  if (use_cb == JNI_TRUE) {
    jclass hdfClass;

    fl_info.env = env;
    fl_info.fl_obj = objClass;
    fl_info.hdf = hdf;

    hdfClass = (*env)->GetObjectClass(env, objClass); 
    if (hdfClass == NULL) return JNI_FALSE;

    fl_info.fl_method = (*env)->GetMethodID(env, hdfClass,
        "fileLoad", "(Ljava/lang/String;)Ljava/lang/String;");
    if (fl_info.fl_method == NULL) return JNI_FALSE;

    hdf_register_fileload(hdf, &fl_info, jni_fileload_cb);
  }

  filename = (*env)->GetStringUTFChars(env, j_filename, 0);
  err = hdf_read_file(hdf, filename);
  (*env)->ReleaseStringUTFChars(env, j_filename, filename);
  if (use_cb == JNI_TRUE) hdf_register_fileload(hdf, NULL, NULL);
  if (err != STATUS_OK) {
    // Throw an exception.  jNeoErr handles all types of errors other than
    // NOT_FOUND, since that can mean different things in different contexts.
    // In this context, it means "file not found".
    if (nerr_match(err, NERR_NOT_FOUND)) {
      STRING str;
      string_init(&str);
      nerr_error_string(err, &str);
      throwFileNotFoundException(env, str.buf);
      string_clear(&str);
    } else {
      jNeoErr(env, err);
    }
  }
  retval = (err == STATUS_OK);
  return retval;
}
Exemple #4
0
    WITH_PLATFORM_STRING(env, path, ps) {
        FD fd;

#if defined(__linux__) || defined(_ALLBSD_SOURCE)
        /* Remove trailing slashes, since the kernel won't */
        char *p = (char *)ps + strlen(ps) - 1;
        while ((p > ps) && (*p == '/'))
            *p-- = '\0';
#endif
        fd = handleOpen(ps, flags, 0666);
        if (fd != -1) {
            jobject fdobj;
            jboolean append;
            SET_FD(this, fd, fid);

            fdobj = (*env)->GetObjectField(env, this, fid);
            if (fdobj != NULL) {
                append = (flags & O_APPEND) == 0 ? JNI_FALSE : JNI_TRUE;
                (*env)->SetBooleanField(env, fdobj, IO_append_fdID, append);
            }
        } else {
            throwFileNotFoundException(env, path);
        }
    } END_PLATFORM_STRING(env, ps);