jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp
author ohair
Sun, 17 Aug 2008 17:02:04 -0700
changeset 1082 53833ff90c45
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux Summary: Removal of compiler warnings and fixing of assert logic. Reviewed-by: jrose, ksrini, bristor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <com_sun_java_util_jar_pack_NativeUnpack.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "bands.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "zip.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static jfieldID  unpackerPtrFID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static jmethodID currentInstMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static jmethodID readInputMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static jclass    NIclazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
static char* dbg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define THROW_IOE(x) JNU_ThrowIOException(env,x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static jlong read_input_via_jni(unpacker* self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                void* buf, jlong minlen, jlong maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    62
  unpacker* uPtr;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    63
  uPtr = (unpacker*)jlong2ptr(env->GetLongField(pObj, unpackerPtrFID));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  //fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  if (uPtr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    if (noCreate)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    uPtr = new unpacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (uPtr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      THROW_IOE(ERROR_ENOMEM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    //fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    uPtr->init(read_input_via_jni);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    75
    env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  uPtr->jnienv = env;  // keep refreshing this in case of MT access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  return uPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
// This is the harder trick:  Pull the current state out of mid-air.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static unpacker* get_unpacker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  //fprintf(stderr, "get_unpacker()\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  JavaVM* vm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  JNI_GetCreatedJavaVMs(&vm, 1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  void* envRaw = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  vm->GetEnv(&envRaw, JNI_VERSION_1_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  JNIEnv* env = (JNIEnv*) envRaw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  //fprintf(stderr, "get_unpacker() env=%p\n", env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  if (env == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  jobject pObj = env->CallStaticObjectMethod(NIclazz, currentInstMID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  //fprintf(stderr, "get_unpacker() pObj=%p\n", pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  if (pObj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  // Got pObj and env; now do it the easy way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  return get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
static void free_unpacker(JNIEnv *env, jobject pObj, unpacker* uPtr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  if (uPtr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    //fprintf(stderr, "free_unpacker(%p) uPtr=%p\n", pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    env->DeleteGlobalRef((jobject) uPtr->jniobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    uPtr->jniobj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    uPtr->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    delete uPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    env->SetLongField(pObj, unpackerPtrFID, (jlong)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
unpacker* unpacker::current() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  return get_unpacker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
// Callback for fetching data, Java style.  Calls NativeUnpack.readInputFn().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static jlong read_input_via_jni(unpacker* self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                void* buf, jlong minlen, jlong maxlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  JNIEnv* env = (JNIEnv*) self->jnienv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  jobject pbuf = env->NewDirectByteBuffer(buf, maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  return env->CallLongMethod((jobject) self->jniobj, readInputMID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                             pbuf, minlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
Java_com_sun_java_util_jar_pack_NativeUnpack_initIDs(JNIEnv *env, jclass clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  dbg = getenv("DEBUG_ATTACH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  while( dbg != null) { sleep(10); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  NIclazz = (jclass) env->NewGlobalRef(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  unpackerPtrFID = env->GetFieldID(clazz, "unpackerPtr", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  currentInstMID = env->GetStaticMethodID(clazz, "currentInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                          "()Ljava/lang/Object;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  readInputMID = env->GetMethodID(clazz, "readInputFn",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                  "(Ljava/nio/ByteBuffer;J)J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  if (unpackerPtrFID == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      currentInstMID == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      readInputMID == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      NIclazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    THROW_IOE("cannot init class members");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                   jobject pBuf, jlong offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  unpacker* uPtr = get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  // redirect our io to the default log file or whatever.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  uPtr->redirect_stdio();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  void*  buf    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  size_t buflen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  if (pBuf != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    buf    = env->GetDirectBufferAddress(pBuf);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   154
    buflen = (size_t)env->GetDirectBufferCapacity(pBuf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    if (buflen == 0)  buf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if ((size_t)offset >= buflen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      { buf = null; buflen = 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      { buf = (char*)buf + (size_t)offset; buflen -= (size_t)offset; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  uPtr->start(buf, buflen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    THROW_IOE(uPtr->get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  return ((jlong)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
          uPtr->get_segments_remaining() << 32)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    + uPtr->get_files_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
Java_com_sun_java_util_jar_pack_NativeUnpack_getNextFile(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                         jobjectArray pParts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  unpacker* uPtr = get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  unpacker::file* filep = uPtr->get_next_file();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    THROW_IOE(uPtr->get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  if (filep == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    return false;   // end of the sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  assert(filep == &uPtr->cur_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  int pidx = 0, iidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  jintArray pIntParts = (jintArray) env->GetObjectArrayElement(pParts, pidx++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  jint*     intParts  = env->GetIntArrayElements(pIntParts, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  intParts[iidx++] = (jint)( (julong)filep->size >> 32 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  intParts[iidx++] = (jint)( (julong)filep->size >>  0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  intParts[iidx++] = filep->modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  intParts[iidx++] = filep->deflate_hint() ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  env->ReleaseIntArrayElements(pIntParts, intParts, JNI_COMMIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  env->SetObjectArrayElement(pParts, pidx++, env->NewStringUTF(filep->name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  jobject pDataBuf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  if (filep->data[0].len > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    pDataBuf = env->NewDirectByteBuffer(filep->data[0].ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                        filep->data[0].len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  env->SetObjectArrayElement(pParts, pidx++, pDataBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  pDataBuf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  if (filep->data[1].len > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    pDataBuf = env->NewDirectByteBuffer(filep->data[1].ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                        filep->data[1].len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  env->SetObjectArrayElement(pParts, pidx++, pDataBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
Java_com_sun_java_util_jar_pack_NativeUnpack_getUnusedInput(JNIEnv *env, jobject pObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  unpacker* uPtr = get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  unpacker::file* filep = &uPtr->cur_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  if (uPtr->aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    THROW_IOE(uPtr->get_abort_message());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  // We have fetched all the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  // Now swallow up any remaining input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  if (uPtr->input_remaining() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return env->NewDirectByteBuffer(uPtr->input_scan(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                    uPtr->input_remaining());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
Java_com_sun_java_util_jar_pack_NativeUnpack_finish(JNIEnv *env, jobject pObj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  unpacker* uPtr = get_unpacker(env, pObj, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  if (uPtr == null)  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  size_t consumed = uPtr->input_consumed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  free_unpacker(env, pObj, uPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  return consumed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
Java_com_sun_java_util_jar_pack_NativeUnpack_setOption(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                       jstring pProp, jstring pValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  unpacker*   uPtr  = get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  const char* prop  = env->GetStringUTFChars(pProp, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  const char* value = env->GetStringUTFChars(pValue, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  jboolean   retval = uPtr->set_option(prop, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  env->ReleaseStringUTFChars(pProp,  prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  env->ReleaseStringUTFChars(pValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
Java_com_sun_java_util_jar_pack_NativeUnpack_getOption(JNIEnv *env, jobject pObj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                       jstring pProp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  unpacker*   uPtr  = get_unpacker(env, pObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  const char* prop  = env->GetStringUTFChars(pProp, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  const char* value = uPtr->get_option(prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  env->ReleaseStringUTFChars(pProp, prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
  if (value == null)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  return env->NewStringUTF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}