harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [169/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/deflater.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/deflater.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/deflater.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/deflater.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,285 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jcl.h"
+#include "iohelp.h"
+
+#include "zlib.h"
+#include "inflater.h"
+#include "jclglob.h"
+#include "jclprots.h"
+
+void zfree PROTOTYPE ((void *opaque, void *address));
+void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
+
+void JNICALL
+Java_java_util_zip_Deflater_setDictionaryImpl (JNIEnv * env, jobject recv,
+                                               jbyteArray dict, int off,
+                                               int len, jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  int err = 0;
+  char *dBytes;
+  JCLZipStream *stream = (JCLZipStream *) handle;
+
+  dBytes = jclmem_allocate_memory (env, len);
+  if (dBytes == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return;
+    }
+  (*env)->GetByteArrayRegion (env, dict, off, len, dBytes);
+  err = deflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
+  if (err != Z_OK)
+    {
+      jclmem_free_memory (env, dBytes);
+      throwNewIllegalArgumentException (env, "");
+      return;
+    }
+  stream->dict = dBytes;
+}
+
+jint JNICALL
+Java_java_util_zip_Deflater_getTotalInImpl (JNIEnv * env, jobject recv,
+                                            jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  return stream->stream->total_in;
+}
+
+int JNICALL
+Java_java_util_zip_Deflater_getTotalOutImpl (JNIEnv * env, jobject recv,
+                                             jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  return stream->stream->total_out;
+}
+
+jint JNICALL
+Java_java_util_zip_Deflater_getAdlerImpl (JNIEnv * env, jobject recv,
+                                          jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+
+  return stream->stream->adler;
+}
+
+/* Create a new stream . This stream cannot be used until it has been properly initialized. */
+jlong JNICALL
+Java_java_util_zip_Deflater_createStream (JNIEnv * env, jobject recv,
+                                          jint level, jint strategy,
+                                          jboolean noHeader)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  JCLZipStream *jstream;
+  z_stream *stream;
+  int err = 0;
+  int wbits = 15;               /*Use MAX for fastest */
+
+  /*Allocate mem for wrapped struct */
+  jstream = jclmem_allocate_memory (env, sizeof (JCLZipStream));
+  if (jstream == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return -1;
+    }
+
+  /*Allocate the z_stream */
+  stream = jclmem_allocate_memory (env, sizeof (z_stream));
+  if (stream == NULL)
+    {
+      jclmem_free_memory (env, jstream);
+      throwNewOutOfMemoryError (env, "");
+      return -1;
+    }
+  stream->opaque = (void *) privatePortLibrary;
+  stream->zalloc = zalloc;
+  stream->zfree = zfree;
+  jstream->stream = stream;
+  jstream->dict = NULL;
+  jstream->inaddr = NULL;
+
+  /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so */
+  if (noHeader)
+    wbits = wbits / -1;
+  err = deflateInit2 (stream, level, Z_DEFLATED,        /*Only supported ZLIB method */
+                      wbits,    /*Window bits to use. 15 is fastest but consumes the most memory */
+                      9,        /*Memory allocation for internal compression state. 9 uses the most. */
+                      strategy);
+  if (err != Z_OK)
+    {
+      throwNewIllegalArgumentException (env, "");
+      return -1;
+    }
+
+  return (jlong) jstream;
+}
+
+void JNICALL
+Java_java_util_zip_Deflater_setInputImpl (JNIEnv * env, jobject recv,
+                                          jbyteArray buf, jint off, jint len,
+                                          jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  jbyte *in;
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  if (stream->inaddr != NULL)   /*Input has already been provided, free the old buffer */
+    jclmem_free_memory (env, stream->inaddr);
+  stream->inaddr = jclmem_allocate_memory (env, len);
+  if (stream->inaddr == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return;
+    }
+  in = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+  if (in == NULL)
+    return;
+  memcpy (stream->inaddr, (in + off), len);
+  ((*env)->ReleasePrimitiveArrayCritical (env, buf, in, JNI_ABORT));
+  stream->stream->next_in = (Bytef *) stream->inaddr;
+  stream->stream->avail_in = len;
+
+  return;
+}
+
+jint JNICALL
+Java_java_util_zip_Deflater_deflateImpl (JNIEnv * env, jobject recv,
+                                         jbyteArray buf, int off, int len,
+                                         jlong handle, int flushParm)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  jbyte *out;
+  JCLZipStream *stream;
+  jint err = 0;
+  jint sin, sout, inBytes = 0;
+
+  /* We need to get the number of bytes already read */
+  inBytes =
+    ((*env)->
+     GetIntField (env, recv,
+                  JCL_CACHE_GET (env, FID_java_util_zip_Deflater_inRead)));
+
+  stream = (JCLZipStream *) handle;
+  stream->stream->avail_out = len;
+  sin = stream->stream->total_in;
+  sout = stream->stream->total_out;
+  out = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+  if (out == NULL)
+    return -1;
+  stream->stream->next_out = (Bytef *) out + off;
+  err = deflate (stream->stream, flushParm);
+  ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
+  if (err != Z_OK)
+    {
+      if (err == Z_STREAM_END)
+        {
+          ((*env)->
+           SetBooleanField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_util_zip_Deflater_finished),
+                            JNI_TRUE));
+          return stream->stream->total_out - sout;
+        }
+    }
+  if (flushParm != Z_FINISH)
+    {
+      /* Need to update the number of input bytes read. */
+
+      ((*env)->
+       SetIntField (env, recv,
+                    JCL_CACHE_GET (env, FID_java_util_zip_Deflater_inRead),
+                    (jint) stream->stream->total_in - sin + inBytes));
+    }
+  return stream->stream->total_out - sout;
+}
+
+void JNICALL
+Java_java_util_zip_Deflater_endImpl (JNIEnv * env, jobject recv, jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+
+  deflateEnd (stream->stream);
+  if (stream->inaddr != NULL)
+    jclmem_free_memory (env, stream->inaddr);
+  if (stream->dict != NULL)
+    jclmem_free_memory (env, stream->dict);
+  jclmem_free_memory (env, stream->stream);
+  jclmem_free_memory (env, stream);
+}
+
+void JNICALL
+Java_java_util_zip_Deflater_resetImpl (JNIEnv * env, jobject recv,
+                                       jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  deflateReset (stream->stream);
+}
+
+void JNICALL
+Java_java_util_zip_Deflater_setLevelsImpl (JNIEnv * env, jobject recv,
+                                           int level, int strategy,
+                                           jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  JCLZipStream *stream;
+  jbyte b = 0;
+  int err = 0;
+
+  if (handle == -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return;
+    }
+  stream = (JCLZipStream *) handle;
+  stream->stream->next_out = (Bytef *) & b;
+  err = deflateParams (stream->stream, level, strategy);
+  if (err != Z_OK)
+    throwNewIllegalStateException (env, "");
+}
+
+void JNICALL
+Java_java_util_zip_Deflater_oneTimeInitialization (JNIEnv * env, jclass clazz)
+{
+  jfieldID fid;
+
+  fid = (*env)->GetFieldID (env, clazz, "inRead", "I");
+  if (!fid)
+    return;
+
+  JCL_CACHE_SET (env, FID_java_util_zip_Deflater_inRead, fid);
+
+  fid = (*env)->GetFieldID (env, clazz, "finished", "Z");
+  if (!fid)
+    return;
+
+  JCL_CACHE_SET (env, FID_java_util_zip_Deflater_finished, fid);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.def
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.def?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.def (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.def Wed Nov 30 21:29:27 2005
@@ -0,0 +1,43 @@
+LIBRARY	HYARCHIVE
+
+SECTIONS
+	.data	READ WRITE
+	.text	EXECUTE READ
+
+EXPORTS
+	Java_java_util_jar_JarFile_getMetaEntriesImpl
+	Java_java_util_zip_Adler32_updateByteImpl
+	Java_java_util_zip_Adler32_updateImpl
+	Java_java_util_zip_CRC32_updateByteImpl
+	Java_java_util_zip_CRC32_updateImpl
+	Java_java_util_zip_Deflater_createStream
+	Java_java_util_zip_Deflater_deflateImpl
+	Java_java_util_zip_Deflater_endImpl
+	Java_java_util_zip_Deflater_getAdlerImpl
+	Java_java_util_zip_Deflater_getTotalInImpl
+	Java_java_util_zip_Deflater_getTotalOutImpl
+	Java_java_util_zip_Deflater_oneTimeInitialization
+	Java_java_util_zip_Deflater_resetImpl
+	Java_java_util_zip_Deflater_setDictionaryImpl
+	Java_java_util_zip_Deflater_setInputImpl
+	Java_java_util_zip_Deflater_setLevelsImpl
+	Java_java_util_zip_Inflater_createStream
+	Java_java_util_zip_Inflater_endImpl
+	Java_java_util_zip_Inflater_getAdlerImpl
+	Java_java_util_zip_Inflater_getTotalInImpl
+	Java_java_util_zip_Inflater_getTotalOutImpl
+	Java_java_util_zip_Inflater_inflateImpl
+	Java_java_util_zip_Inflater_oneTimeInitialization
+	Java_java_util_zip_Inflater_resetImpl
+	Java_java_util_zip_Inflater_setDictionaryImpl
+	Java_java_util_zip_Inflater_setInputImpl
+	Java_java_util_zip_ZipFile_00024ZFEnum_getNextEntry
+	Java_java_util_zip_ZipFile_00024ZFEnum_resetZip
+	Java_java_util_zip_ZipFile_closeZipImpl
+	Java_java_util_zip_ZipFile_getEntryImpl
+	Java_java_util_zip_ZipFile_inflateEntryImpl2
+	Java_java_util_zip_ZipFile_ntvinit
+	Java_java_util_zip_ZipFile_openZipImpl
+	JNI_OnLoad
+	JNI_OnUnload
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.rc
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.rc?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.rc (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/hyarchive.rc Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+;
+; Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+; 
+; Licensed under the Apache License, Version 2.0 (the "License");
+; you may not use this file except in compliance with the License.
+; You may obtain a copy of the License at
+; 
+;     http://www.apache.org/licenses/LICENSE-2.0
+; 
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+;
+
+#include <windows.h>
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 0,1,0,0
+ PRODUCTVERSION 0,1,0,0
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0x0L
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+	BLOCK "StringFileInfo"
+	BEGIN
+		BLOCK "040904b0"
+		BEGIN
+			VALUE "CompanyName", "The Apache Software Foundation.\0"
+			VALUE "FileDescription", "Archive element native code\0"
+			VALUE "FileVersion", "0.1\0"
+			VALUE "InternalName", "archive\0"
+			VALUE "LegalCopyright", "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.\0"
+			VALUE "OriginalFilename", "hyarchive.dll\0"
+			VALUE "ProductName", "Apache Harmony\0"
+			VALUE "ProductVersion", "0.1\0"
+		END
+	END
+	BLOCK "VarFileInfo"
+	BEGIN
+		VALUE "Translation", 0x0409, 1200
+	END
+END

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,292 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jcl.h"
+#include "iohelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+#include "inflater.h"
+
+void throwNewDataFormatException (JNIEnv * env, char *message);
+
+/* Create a new stream . This stream cannot be used until it has been properly initialized. */
+jlong JNICALL
+Java_java_util_zip_Inflater_createStream (JNIEnv * env, jobject recv,
+                                          jboolean noHeader)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  JCLZipStream *jstream;
+  z_stream *stream;
+  int err = 0;
+  int wbits = 15;               /*Use MAX for fastest */
+
+  /*Allocate mem for wrapped struct */
+  jstream = jclmem_allocate_memory (env, sizeof (JCLZipStream));
+  if (jstream == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return -1;
+    }
+  /*Allocate the z_stream */
+  stream = jclmem_allocate_memory (env, sizeof (z_stream));
+  if (stream == NULL)
+    {
+      jclmem_free_memory (env, jstream);
+      throwNewOutOfMemoryError (env, "");
+      return -1;
+    }
+
+  stream->opaque = (void *) privatePortLibrary;
+  stream->zalloc = zalloc;
+  stream->zfree = zfree;
+  stream->adler = 1;
+  jstream->stream = stream;
+  jstream->dict = NULL;
+  jstream->inaddr = NULL;
+
+  /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so. */
+  if (noHeader)
+    wbits = wbits / -1;
+  err = inflateInit2 (stream, wbits);   /*Window bits to use. 15 is fastest but consumes the most memory */
+
+  if (err != Z_OK)
+    {
+      jclmem_free_memory (env, stream);
+      jclmem_free_memory (env, jstream);
+      throwNewIllegalArgumentException (env, "");
+      return -1;
+    }
+
+  return (jlong) jstream;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_setInputImpl (JNIEnv * env, jobject recv,
+                                          jbyteArray buf, jint off, jint len,
+                                          jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  jbyte *in;
+  U_8 *baseAddr;
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+
+  if (stream->inaddr != NULL)   /*Input has already been provided, free the old buffer */
+    jclmem_free_memory (env, stream->inaddr);
+  baseAddr = jclmem_allocate_memory (env, len);
+  if (baseAddr == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return;
+    }
+  stream->inaddr = baseAddr;
+  stream->stream->next_in = (Bytef *) baseAddr;
+  stream->stream->avail_in = len;
+  in = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+  if (in == NULL)
+    return;
+  memcpy (baseAddr, (in + off), len);
+  ((*env)->ReleasePrimitiveArrayCritical (env, buf, in, JNI_ABORT));
+  return;
+}
+
+jint JNICALL
+Java_java_util_zip_Inflater_inflateImpl (JNIEnv * env, jobject recv,
+                                         jbyteArray buf, int off, int len,
+                                         jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  jbyte *out;
+  JCLZipStream *stream;
+  jint err = 0;
+  jfieldID fid = 0, fid2 = 0;
+  jint sin, sout, inBytes = 0;
+
+  /* We need to get the number of bytes already read */
+  fid = JCL_CACHE_GET (env, FID_java_util_zip_Inflater_inRead);
+  inBytes = ((*env)->GetIntField (env, recv, fid));
+
+  stream = (JCLZipStream *) handle;
+  stream->stream->avail_out = len;
+  sin = stream->stream->total_in;
+  sout = stream->stream->total_out;
+  out = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+  if (out == NULL)
+    return -1;
+  stream->stream->next_out = (Bytef *) out + off;
+  err = inflate (stream->stream, Z_SYNC_FLUSH);
+  ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
+
+  if (err != Z_OK)
+    {
+      if (err == Z_STREAM_END || err == Z_NEED_DICT)
+        {
+          ((*env)->SetIntField (env, recv, fid, (jint) stream->stream->total_in - sin + inBytes));      /* Update inRead */
+          if (err == Z_STREAM_END)
+            fid2 = JCL_CACHE_GET (env, FID_java_util_zip_Inflater_finished);
+          else
+            fid2 =
+              JCL_CACHE_GET (env, FID_java_util_zip_Inflater_needsDictionary);
+
+          ((*env)->SetBooleanField (env, recv, fid2, JNI_TRUE));
+          return stream->stream->total_out - sout;
+        }
+      else
+        {
+          throwNewDataFormatException (env, "");
+          return -1;
+        }
+    }
+
+  /* Need to update the number of input bytes read. Is there a better way(Maybe global the fid then delete when end
+     is called)? */
+  ((*env)->
+   SetIntField (env, recv, fid,
+                (jint) stream->stream->total_in - sin + inBytes));
+
+  return stream->stream->total_out - sout;
+}
+
+jint JNICALL
+Java_java_util_zip_Inflater_getAdlerImpl (JNIEnv * env, jobject recv,
+                                          jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+
+  return stream->stream->adler;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_endImpl (JNIEnv * env, jobject recv, jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  inflateEnd (stream->stream);
+  if (stream->inaddr != NULL)   /*Input has been provided, free the buffer */
+    jclmem_free_memory (env, stream->inaddr);
+  if (stream->dict != NULL)
+    jclmem_free_memory (env, stream->dict);
+  jclmem_free_memory (env, stream->stream);
+  jclmem_free_memory (env, stream);
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_setDictionaryImpl (JNIEnv * env, jobject recv,
+                                               jbyteArray dict, int off,
+                                               int len, jlong handle)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  int err = 0;
+  U_8 *dBytes;
+  JCLZipStream *stream = (JCLZipStream *) handle;
+
+  dBytes = jclmem_allocate_memory (env, len);
+  if (dBytes == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return;
+    }
+  (*env)->GetByteArrayRegion (env, dict, off, len, dBytes);
+  err = inflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
+  if (err != Z_OK)
+    {
+      jclmem_free_memory (env, dBytes);
+      throwNewIllegalArgumentException (env, "");
+      return;
+    }
+  stream->dict = dBytes;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_resetImpl (JNIEnv * env, jobject recv,
+                                       jlong handle)
+{
+  JCLZipStream *stream;
+  int err = 0;
+  stream = (JCLZipStream *) handle;
+
+  err = inflateReset (stream->stream);
+  if (err != Z_OK)
+    {
+      throwNewIllegalArgumentException (env, "");
+      return;
+    }
+}
+
+/**
+  * Throw java.util.zip.DataFormatException
+  */
+void
+throwNewDataFormatException (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/util/zip/DataFormatException");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+int JNICALL
+Java_java_util_zip_Inflater_getTotalOutImpl (JNIEnv * env, jobject recv,
+                                             jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  return stream->stream->total_out;
+}
+
+int JNICALL
+Java_java_util_zip_Inflater_getTotalInImpl (JNIEnv * env, jobject recv,
+                                            jlong handle)
+{
+  JCLZipStream *stream;
+
+  stream = (JCLZipStream *) handle;
+  return stream->stream->total_in;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_oneTimeInitialization (JNIEnv * env, jclass clazz)
+{
+  jfieldID fid;
+
+  fid = (*env)->GetFieldID (env, clazz, "inRead", "I");
+  if (!fid)
+    return;
+
+  JCL_CACHE_SET (env, FID_java_util_zip_Inflater_inRead, fid);
+
+  fid = (*env)->GetFieldID (env, clazz, "finished", "Z");
+  if (!fid)
+    return;
+
+  JCL_CACHE_SET (env, FID_java_util_zip_Inflater_finished, fid);
+
+  fid = (*env)->GetFieldID (env, clazz, "needsDictionary", "Z");
+  if (!fid)
+    return;
+
+  JCL_CACHE_SET (env, FID_java_util_zip_Inflater_needsDictionary, fid);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/inflater.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,75 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(inflater_h)
+#define inflater_h
+
+#include "zlib.h"
+
+typedef struct JCLZipStream
+{
+  U_8 *inaddr;
+  U_8 *dict;
+  z_stream *stream;
+} JCLZipStream;
+
+void zfree PROTOTYPE ((void *opaque, void *address));
+
+void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
+
+void JNICALL Java_java_util_zip_Inflater_endImpl (JNIEnv * env, jobject recv,
+                                                  jlong handle);
+
+void JNICALL Java_java_util_zip_Inflater_setInputImpl (JNIEnv * env,
+                                                       jobject recv,
+                                                       jbyteArray buf,
+                                                       jint off, jint len,
+                                                       jlong handle);
+
+jint JNICALL Java_java_util_zip_Inflater_inflateImpl (JNIEnv * env,
+                                                      jobject recv,
+                                                      jbyteArray buf, int off,
+                                                      int len, jlong handle);
+
+void JNICALL Java_java_util_zip_Inflater_setDictionaryImpl (JNIEnv * env,
+                                                            jobject recv,
+                                                            jbyteArray dict,
+                                                            int off, int len,
+                                                            jlong handle);
+
+void JNICALL Java_java_util_zip_Inflater_oneTimeInitialization (JNIEnv * env,
+                                                                jclass clazz);
+
+void JNICALL Java_java_util_zip_Inflater_resetImpl (JNIEnv * env,
+                                                    jobject recv,
+                                                    jlong handle);
+
+int JNICALL Java_java_util_zip_Inflater_getTotalOutImpl (JNIEnv * env,
+                                                         jobject recv,
+                                                         jlong handle);
+
+jlong JNICALL Java_java_util_zip_Inflater_createStream (JNIEnv * env,
+                                                        jobject recv,
+                                                        jboolean noHeader);
+
+int JNICALL Java_java_util_zip_Inflater_getTotalInImpl (JNIEnv * env,
+                                                        jobject recv,
+                                                        jlong handle);
+
+jint JNICALL Java_java_util_zip_Inflater_getAdlerImpl (JNIEnv * env,
+                                                       jobject recv,
+                                                       jlong handle);
+
+#endif /* inflater_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,79 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "iohelp.h"
+#include "jclglob.h"
+
+void
+ioh_convertToPlatform (char *path)
+{
+  char *pathIndex;
+  int length = strlen (path);
+
+  /* Convert all separators to the same type */
+  pathIndex = path;
+  while (*pathIndex != '\0')
+    {
+      if ((*pathIndex == '\\' || *pathIndex == '/')
+          && (*pathIndex != jclSeparator))
+        *pathIndex = jclSeparator;
+      pathIndex++;
+    }
+
+  /* Remove duplicate separators */
+  if (jclSeparator == '/')
+    return;                     /* Do not do POSIX platforms */
+
+  /* Remove duplicate initial separators */
+  pathIndex = path;
+  while ((*pathIndex != '\0') && (*pathIndex == jclSeparator))
+    {
+      pathIndex++;
+    }
+
+  if ((pathIndex > path) && (length > (pathIndex - path))
+      && (*(pathIndex + 1) == ':'))
+    {
+      /* For Example '////c:/*' */
+      int newlen = length - (pathIndex - path);
+      memmove (path, pathIndex, newlen);
+      path[newlen] = '\0';
+    }
+  else
+    {
+      if ((pathIndex - path > 3) && (length > (pathIndex - path)))
+        {
+          /* For Example '////serverName/*' */
+          int newlen = length - (pathIndex - path) + 2;
+          memmove (path, pathIndex - 2, newlen);
+          path[newlen] = '\0';
+        }
+    }
+  /* This will have to handle extra \'s but currently doesn't */
+}
+
+/**
+  * Throw java.lang.OutOfMemoryError
+  */
+void
+throwNewOutOfMemoryError (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/iohelp.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,28 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(iohelp_h)
+#define iohelp_h
+
+#include <string.h>
+#include "jcl.h"
+
+/* DIR_SEPARATOR is defined in hycomp.h */
+#define jclSeparator DIR_SEPARATOR
+
+void throwNewOutOfMemoryError (JNIEnv * env, char *message);
+void ioh_convertToPlatform (char *path);
+
+#endif /* iohelp_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jarfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jarfile.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jarfile.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jarfile.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,171 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jcl.h"
+#include "iohelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+#include "zipsup.h"
+
+/* Build a new ZipEntry from the C struct */
+jobject
+createZipEntry (JNIEnv * env, HyZipFile * zipFile, HyZipEntry * zipEntry)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jclass javaClass;
+  jobject java_ZipEntry, extra, entryName;
+  jmethodID mid;
+
+  /* Build a new ZipEntry from the C struct */
+  entryName = ((*env)->NewStringUTF (env, zipEntry->filename));
+  if (((*env)->ExceptionCheck (env)))
+    return NULL;
+
+  extra = NULL;
+  if (zipEntry->extraFieldLength > 0)
+    {
+      zip_getZipEntryExtraField (PORTLIB, zipFile, zipEntry, NULL,
+                                 zipEntry->extraFieldLength);
+      if (zipEntry->extraField == NULL)
+        return NULL;
+      extra = ((*env)->NewByteArray (env, zipEntry->extraFieldLength));
+      if (((*env)->ExceptionCheck (env)))
+        return NULL;
+      ((*env)->
+       SetByteArrayRegion (env, extra, 0, zipEntry->extraFieldLength,
+                           zipEntry->extraField));
+      jclmem_free_memory (env, zipEntry->extraField);
+      zipEntry->extraField = NULL;
+    }
+
+  javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+  mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+  java_ZipEntry = ((*env)->NewObject (env, javaClass, mid, entryName, NULL,
+                                      extra,
+                                      (jlong) zipEntry->lastModTime,
+                                      (jlong) zipEntry->uncompressedSize,
+                                      (jlong) zipEntry->compressedSize,
+                                      (jlong) zipEntry->crc32,
+                                      zipEntry->compressionMethod,
+                                      (jlong) zipEntry->lastModDate,
+                                      (jlong) zipEntry->dataPointer));
+  return java_ZipEntry;
+}
+
+jarray JNICALL
+Java_java_util_jar_JarFile_getMetaEntriesImpl (JNIEnv * env, jobject recv,
+                                               jbyteArray zipName)
+{
+#define MAX_PATH	1024
+#define RESULT_BUF_SIZE 256
+
+  PORT_ACCESS_FROM_ENV (env);
+
+  JCLZipFile *jclZipFile;
+  HyZipFile *zipFile;
+  HyZipEntry zipEntry;
+  jobject current;
+  jclass javaClass;
+  jobject resultArray[RESULT_BUF_SIZE];
+  UDATA resultCount = 0, offset, i;
+  void *scanPtr;
+  char metaInfName[10];         /* 10 == strlen("META-INF/") + 1 */
+  const UDATA metaInfSize = 10; /* 10 == strlen("META-INF/") + 1 */
+  jobjectArray result = NULL;
+  char *nameBuf, *newNameBuf, *oldNameBuf = NULL;
+  char startNameBuf[MAX_PATH];
+  UDATA nameBufSize = MAX_PATH;
+  IDATA rc;
+
+  nameBuf = (char *) &startNameBuf;
+
+  jclZipFile =
+    (JCLZipFile *) (*env)->GetLongField (env, recv,
+                                         JCL_CACHE_GET (env,
+                                                        FID_java_util_zip_ZipFile_descriptor));
+  if (jclZipFile == (void *) -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return NULL;
+    }
+  zipFile = &(jclZipFile->hyZipFile);
+
+  if (zipFile->cache)
+    {
+      if (zipCache_enumNew (zipFile->cache, "META-INF/", &scanPtr))
+        return NULL;
+
+      if (0 !=
+          zipCache_enumGetDirName (scanPtr, (char *) &metaInfName,
+                                   sizeof (metaInfName)))
+        return NULL;
+
+      for (;;)
+        {
+          rc = zipCache_enumElement (scanPtr, nameBuf, nameBufSize, &offset);
+          if (rc < 0)
+            {
+              break;            /* we're done, leave the loop */
+            }
+          else if (rc > 0)
+            {
+              /* the buffer wasn't big enough, grow it */
+              newNameBuf = jclmem_allocate_memory (env, rc);
+              nameBufSize = rc;
+              if (oldNameBuf)
+                {
+                  jclmem_free_memory (env, oldNameBuf); /* free old before checking result so we clean up on fail */
+                  oldNameBuf = NULL;
+                }
+              if (!newNameBuf)
+                goto cleanup;
+              nameBuf = oldNameBuf = newNameBuf;
+              continue;         /* go to the top of the loop again */
+            }
+
+          zip_initZipEntry (PORTLIB, &zipEntry);
+          if (zip_getZipEntryFromOffset (PORTLIB, zipFile, &zipEntry, offset))
+            goto cleanup;
+          current = createZipEntry (env, zipFile, &zipEntry);
+          zip_freeZipEntry (PORTLIB, &zipEntry);
+          if (resultCount == RESULT_BUF_SIZE)
+            goto cleanup;       /* fail - should fix. */
+          if (current)
+            resultArray[resultCount++] = current;
+          else
+            goto cleanup;
+        }
+      javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+      result = ((*env)->NewObjectArray (env, resultCount, javaClass, NULL));
+      if (((*env)->ExceptionCheck (env)))
+        {
+          result = NULL;
+          goto cleanup;
+        }
+      for (i = 0; i < resultCount; i++)
+        {
+          (*env)->SetObjectArrayElement (env, result, i, resultArray[i]);
+        }
+    cleanup:
+      zipCache_enumKill (scanPtr);
+      if (oldNameBuf)
+        jclmem_free_memory (env, oldNameBuf);   /* free old before checking result so we clean up on fail */
+      return result;
+    }
+  return NULL;
+
+#undef MAX_PATH
+#undef RESULT_BUF_SIZE
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jcl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jcl.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jcl.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jcl.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,22 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(jcl_h)
+#define jcl_h
+
+#define USING_VMI
+#include "vmi.h"
+
+#endif /* jcl_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclcrc32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclcrc32.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclcrc32.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclcrc32.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "jcl.h"
+#include "zconf.h"
+
+uLong crc32 PROTOTYPE ((uLong crc, const Bytef * buf, uInt size));
+
+jlong JNICALL
+Java_java_util_zip_CRC32_updateImpl (JNIEnv * env, jobject recv,
+                                     jbyteArray buf, int off, int len,
+                                     jlong crc)
+{
+  jbyte *b;
+  jlong result;
+
+  b = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+  if (b == NULL)
+    return -1;
+  result = crc32 ((uLong) crc, (Bytef *) (b + off), (uInt) len);
+  ((*env)->ReleasePrimitiveArrayCritical (env, buf, b, JNI_ABORT));
+  return result;
+}
+
+jlong JNICALL
+Java_java_util_zip_CRC32_updateByteImpl (JNIEnv * env, jobject recv,
+                                         jbyte val, jlong crc)
+{
+  return crc32 ((uLong) crc, (Bytef *) (&val), 1);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(jclglob_h)
+#define jclglob_h
+
+#include "jcl.h"
+#include "zip.h"
+
+extern void *Archive_JCL_ID_CACHE;
+
+#define JCL_ID_CACHE Archive_JCL_ID_CACHE
+
+typedef struct ArchiveJniIDCache
+{
+  jfieldID FID_java_util_zip_ZipFile_descriptor;
+  jfieldID FID_java_util_zip_ZipFile_nextEntryPointer;
+  jfieldID FID_java_util_zip_Deflater_inRead;
+  jfieldID FID_java_util_zip_Deflater_finished;
+  jfieldID FID_java_util_zip_Inflater_inRead;
+  jfieldID FID_java_util_zip_Inflater_finished;
+  jfieldID FID_java_util_zip_Inflater_needsDictionary;
+  jmethodID MID_java_util_zip_ZipEntry_init;
+
+  jclass CLS_java_util_zip_ZipEntry;
+  JCLZipFileLink *zipfile_handles;
+} ArchiveJniIDCache;
+
+#define JniIDCache ArchiveJniIDCache
+
+/* Now that the module-specific defines are in place, include the shared file */
+#include "libglob.h"
+
+#endif /* jclglob_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob_harmony.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob_harmony.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob_harmony.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/jclglob_harmony.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,606 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * @ingroup HarmonyNatives
+ * @brief Harmony natives initialization API.
+ */
+
+#include <string.h>
+#include "jcl.h"
+#include "jclglob.h"
+#include "zipsup.h"
+#include "hypool.h"
+
+static UDATA keyInitCount = 0;
+
+void *JCL_ID_CACHE = NULL;
+
+/**
+  * A structure that captures a single key-value setting from the properties file.
+  */
+typedef struct props_file_entry
+{
+  char *key;                            /**< The key as it appears in the properties file */
+  char *value;                          /**< The value as it appears in the properties file */
+} props_file_entry;
+
+jint handleOnLoadEvent (JavaVM * vm);
+jint decodeProperty (HyPortLibrary * portLibrary, char **scanCursor,
+                     HyPool * properties);
+jint readPropertiesFile (HyPortLibrary * portLibrary, char *filename,
+                         HyPool * properties);
+void freeHack (JNIEnv * env);
+void *jclCachePointer (JNIEnv * env);
+jint readClassPathFromPropertiesFile (JavaVM * vm);
+char *concat (HyPortLibrary * portLibrary, ...);
+
+/**
+ * @internal
+ */
+void
+freeHack (JNIEnv * env)
+{
+  jclass classRef;
+
+  /* clean up class references */
+  classRef = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+  if (classRef)
+    (*env)->DeleteWeakGlobalRef (env, (jweak) classRef);
+}
+
+/**
+ * This DLL is being loaded, do any initialization required.
+ * This may be called more than once.
+ */
+jint JNICALL
+JNI_OnLoad (JavaVM * vm, void *reserved)
+{
+  jint rcOnLoad, rcBpInit;
+
+  /* Shared initialization */
+  rcOnLoad = handleOnLoadEvent (vm);
+  if (!rcOnLoad)
+    {
+      return 0;
+    }
+
+  /* Initialize bootstrap classpath */
+  rcBpInit = readClassPathFromPropertiesFile (vm);
+  if (JNI_OK != rcBpInit)
+    {
+      return 0;
+    }
+
+  return rcOnLoad;
+}
+
+/**
+ * This DLL is being unloaded, do any clean up required.
+ * This may be called more than once!!
+ */
+void JNICALL
+JNI_OnUnload (JavaVM * vm, void *reserved)
+{
+  JNIEnv *env;
+  void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+  void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+
+  int i, listlen;
+  char **portArray, **portArray2;
+
+  if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK)
+    {
+      JniIDCache *idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+
+      if (idCache)
+        {
+          PORT_ACCESS_FROM_ENV (env);
+
+          JCLZipFileLink *zipfileHandles;
+          JCLZipFile *jclZipFile;
+
+          /* Close and free the HyZipFile handles */
+          zipfileHandles = JCL_CACHE_GET (env, zipfile_handles);
+          if (zipfileHandles != NULL)
+            {
+              jclZipFile = zipfileHandles->next;
+              while (jclZipFile != NULL)
+                {
+                  JCLZipFile *next = jclZipFile->next;
+                  zip_closeZipFile (PORTLIB, &jclZipFile->hyZipFile);
+                  jclmem_free_memory (env, jclZipFile);
+                  jclZipFile = next;
+                }
+              jclmem_free_memory (env, zipfileHandles);
+            }
+
+          freeHack (env);
+
+          /* Free VMLS keys */
+          idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+          HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr,
+                                              jclIdCache, NULL);
+          hymem_free_memory (idCache);
+        }
+    }
+}
+
+/**
+ * @internal
+ * This DLL is being loaded, do any initialization required.
+ * This may be called more than once.
+ */
+jint
+handleOnLoadEvent (JavaVM * vm)
+{
+  JniIDCache *idCache;
+  JNIEnv *env;
+  void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+  void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+
+#if defined(LINUX)
+  /* all UNIX platforms */
+  HySignalHandler previousGpHandler;
+  HySigSet (SIGPIPE, SIG_IGN, previousGpHandler);
+#endif
+
+  if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK)
+    {
+      PORT_ACCESS_FROM_ENV (env);
+
+      if (HY_VMLS_FNTBL (env)->
+          HYVMLSAllocKeys (env, keyInitCountPtr, jclIdCache, NULL))
+        {
+          goto fail;
+        }
+
+      idCache = (JniIDCache *) hymem_allocate_memory (sizeof (JniIDCache));
+      if (!idCache)
+        goto fail2;
+
+      memset (idCache, 0, sizeof (JniIDCache));
+      HY_VMLS_SET (env, *jclIdCache, idCache);
+
+      return JNI_VERSION_1_2;
+    }
+
+fail2:
+  HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr, jclIdCache, NULL);
+fail:
+  return 0;
+}
+
+/**
+ * Concatenates a variable number of null-terminated strings into a single string
+ * using the specified port library to allocate memory.  The variable number of
+ * strings arguments must be terminated by a single NULL value.
+ *
+ * @param portLibrary - The port library used to allocate memory.
+ * @return The concatenated string.
+ */
+char *
+concat (HyPortLibrary * portLibrary, ...)
+{
+  PORT_ACCESS_FROM_PORT (portLibrary);
+  va_list argp;
+  char *concatenated;
+  UDATA concatenatedSize = 0;
+
+  /* Walk the variable arguments once to compute the final size */
+  va_start (argp, portLibrary);
+  while (1)
+    {
+      char *chunk = va_arg (argp, char *);
+      if (chunk)
+        {
+          concatenatedSize += strlen (chunk);
+        }
+      else
+        {
+          break;
+        }
+    }
+  va_end (argp);
+
+  /* Allocate concatenated space */
+  concatenated =
+    hymem_allocate_memory (concatenatedSize + 1 /* for null terminator */ );
+  if (!concatenated)
+    {
+      return NULL;
+    }
+  concatenated[0] = '\0';
+
+  /* Walk again concatenating the pieces */
+  va_start (argp, portLibrary);
+  while (1)
+    {
+      char *chunk = va_arg (argp, char *);
+      if (chunk)
+        {
+          strcat (concatenated, chunk);
+        }
+      else
+        {
+          break;
+        }
+    }
+  va_end (argp);
+
+  return concatenated;
+}
+
+/**
+  * Read the properties file specified by <tt>filename</tt> into the pool of <tt>properties</tt>.
+  *
+  * @param portLibrary - The port library used to interact with the platform.
+  * @param filename - The file from which to read data using hyfile* functions.
+  * @param properties - A pool that will contain property file entries.
+  *
+  * @return JNI_OK on success, or a JNI error code on failure.
+  */
+jint
+readPropertiesFile (HyPortLibrary * portLibrary, char *filename,
+                    HyPool * properties)
+{
+  PORT_ACCESS_FROM_PORT (portLibrary);
+  IDATA propsFD = -1;
+  I_64 seekResult;
+  IDATA fileSize;
+  IDATA bytesRemaining;
+  jint returnCode = JNI_OK;
+  char *fileContents = NULL;
+  char *writeCursor;
+  char *scanCursor, *scanLimit;
+
+  /* Determine the file size, fail if > 2G */
+  seekResult = hyfile_length (filename);
+  if ((seekResult <= 0) || (seekResult > 0x7FFFFFFF))
+    {
+      return JNI_ERR;
+    }
+  fileSize = (IDATA) seekResult;
+
+  /* Open the properties file */
+  propsFD = hyfile_open (filename, (I_32) HyOpenRead, (I_32) 0);
+  if (propsFD == -1)
+    {
+      /* Could not open the file */
+      return JNI_ERR;
+    }
+
+  /* Allocate temporary storage */
+  fileContents = hymem_allocate_memory (fileSize);
+  if (!fileContents)
+    {
+      return JNI_ENOMEM;
+    }
+
+  /* Initialize the read state */
+  bytesRemaining = fileSize;
+  writeCursor = fileContents;
+
+  /* Suck the file into memory */
+  while (bytesRemaining > 0)
+    {
+      IDATA bytesRead = hyfile_read (propsFD, writeCursor, bytesRemaining);
+      if (bytesRead == -1)
+        {
+          /* Read failed */
+          returnCode = JNI_ERR;
+          goto bail;
+        }
+
+      /* Advance the read state */
+      bytesRemaining -= bytesRead;
+      writeCursor += bytesRead;
+    }
+
+  /* Set up scan and limit points */
+  scanCursor = fileContents;
+  scanLimit = fileContents + fileSize;
+
+  /* Now crack the properties */
+  while (scanCursor < scanLimit)
+    {
+      /* Decode a property and advance the scan cursor */
+      int numberDecoded = decodeProperty (PORTLIB, &scanCursor, properties);
+
+      /* Bail if we encounter an error */
+      if (numberDecoded < 0)
+        {
+          returnCode = JNI_ENOMEM;
+          break;
+        }
+    }
+
+bail:
+  if (propsFD != -1)
+    {
+      hyfile_close (propsFD);
+    }
+  if (fileContents)
+    {
+      hymem_free_memory (fileContents);
+    }
+
+  return returnCode;
+}
+
+/**
+   * Scans the buffer specified by scanCursor and attempts to locate the next
+  *  key-value pair separated by the '=' sign, and terminated by the platform line
+  * delimiter.
+  * 
+  * If a key-value pair is located a new props_file_entry structure will be allocated in
+  * the <tt>properties</tt> pool, and the key and value will be copied.  The scanCursor
+  * will be advanced past the entire property entry on success.
+  *
+  * @param portLibrary - The port library used to interact with the platform.
+  * @param scanCursor - A null-terminated string containing one or more (or partial) properties.
+  * @param properties - A pool from which props_file_entry structures are allocated.
+  *
+  * @return The number of properties read, -1 on error.
+  * @note This function modifies the buffer as properties are consumed.
+  */
+jint
+decodeProperty (HyPortLibrary * portLibrary, char **scanCursor,
+                HyPool * properties)
+{
+  PORT_ACCESS_FROM_PORT (portLibrary);
+  props_file_entry *property;
+  int keyLength, valueLength;
+  char *equalSign;
+  char *lineDelimiter;
+  char *propertyBuffer = *scanCursor;
+
+  lineDelimiter = strstr (propertyBuffer, PLATFORM_LINE_DELIMITER);
+  if (lineDelimiter)
+    {
+      /* Hammer the line delimiter to be a null */
+      *lineDelimiter = '\0';
+      *scanCursor = lineDelimiter + strlen (PLATFORM_LINE_DELIMITER);
+    }
+  else
+    {
+      /* Assume the entire text is a single token */
+      *scanCursor = propertyBuffer + strlen (propertyBuffer) - 1;
+    }
+
+  /* Now find the '=' character */
+  equalSign = strchr (propertyBuffer, '=');
+  if (!equalSign)
+    {
+      /* Malformed, assume it's a comment and move on */
+      return 0;
+    }
+
+  /* Allocate a new pool entry */
+  property = pool_newElement (properties);
+  if (!property)
+    {
+      return 0;
+    }
+
+  /* Compute the key length and allocate memory */
+  keyLength = equalSign - propertyBuffer;
+  property->key =
+    hymem_allocate_memory (keyLength + 1 /* for null terminator */ );
+  if (!property->key)
+    {
+      goto bail;
+    }
+
+  /* Compute the value length and allocate memory */
+  memcpy (property->key, propertyBuffer, keyLength);
+  property->key[keyLength] = '\0';
+
+  /* Compute the value length and allocate memory */
+  valueLength = strlen (propertyBuffer) - keyLength - 1 /* for equal sign */ ;
+  property->value =
+    hymem_allocate_memory (valueLength + 1 /* for null terminator */ );
+  if (!property->value)
+    {
+      goto bail;
+    }
+
+  /* Compute the value length and allocate memory */
+  memcpy (property->value, equalSign + 1, valueLength);
+  property->value[valueLength] = '\0';
+
+  /* Advance the scan cursor */
+  return 1;
+
+bail:
+  if (property != NULL)
+    {
+      if (property->key)
+        {
+          hymem_free_memory (property->key);
+        }
+      if (property->value)
+        {
+          hymem_free_memory (property->value);
+        }
+      pool_removeElement (properties, property);
+    }
+
+  return -1;
+}
+
+/**
+ * Initializes the bootstrap classpath used by the VM.
+ *
+ * Reads the bootclasspath.properties file a line at a time 
+ *
+ * @param vm - The JavaVM from which port library and VMI interfaces can be obtained.
+ *
+ * @return - JNI_OK on success.
+ */
+jint
+readClassPathFromPropertiesFile (JavaVM * vm)
+{
+  VMInterface *vmInterface;
+  HyPortLibrary *privatePortLibrary;
+  char *javaHome;
+  char bootDirectory[HyMaxPath];
+  char propsFile[HyMaxPath];
+  char cpSeparator[2];
+  char *bootstrapClassPath = NULL;
+  char *fileWritePos;
+  vmiError rcGetProperty;
+  jint returnCode = JNI_OK;
+  IDATA propsFD = -1;
+  HyPool *properties;
+
+  /* Query the VM interface */
+  vmInterface = VMI_GetVMIFromJavaVM (vm);
+  if (!vmInterface)
+    {
+      return JNI_ERR;
+    }
+
+  /* Extract the port library */
+  privatePortLibrary = (*vmInterface)->GetPortLibrary (vmInterface);
+  if (!privatePortLibrary)
+    {
+      return JNI_ERR;
+    }
+
+  /* Make a string version of the CP separator */
+  cpSeparator[0] = hysysinfo_get_classpathSeparator ();
+  cpSeparator[1] = '\0';
+
+  /* Load the java.home system property */
+  rcGetProperty =
+    (*vmInterface)->GetSystemProperty (vmInterface, "java.home", &javaHome);
+  if (VMI_ERROR_NONE != rcGetProperty)
+    {
+      return JNI_ERR;
+    }
+
+  /* Locate the boot directory in ${java.home}\lib\boot */
+  strcpy (bootDirectory, javaHome);
+
+  /* Tack on a trailing separator if needed */
+  if (bootDirectory[strlen (javaHome) - 1] != DIR_SEPARATOR)
+    {
+      strcat (bootDirectory, DIR_SEPARATOR_STR);
+    }
+
+  /* Now tack on the lib/boot portion */
+  strcat (bootDirectory, "lib");
+  strcat (bootDirectory, DIR_SEPARATOR_STR);
+  strcat (bootDirectory, "boot");
+  strcat (bootDirectory, DIR_SEPARATOR_STR);
+
+  /* Build up the location of the properties file relative to java.home */
+  propsFile[0] = '\0';
+  strcat (propsFile, bootDirectory);
+  strcat (propsFile, "bootclasspath.properties");
+
+  /* Create a pool to hold onto properties */
+  properties =
+    pool_new (sizeof (props_file_entry), 0, 0, 0, POOL_FOR_PORT (PORTLIB));
+  if (!properties)
+    {
+      returnCode = JNI_ENOMEM;
+      goto cleanup;
+    }
+
+  /* Pull the properties into the pool */
+  if (JNI_OK == readPropertiesFile (PORTLIB, propsFile, properties))
+    {
+      pool_state poolState;
+
+      props_file_entry *property = pool_startDo (properties, &poolState);
+      while (property)
+        {
+          int digit;
+          int tokensScanned =
+            sscanf (property->key, "bootclasspath.%d", &digit);
+
+          /* Ignore anything except bootclasspath.<digit> */
+          if (tokensScanned == 1)
+            {
+
+              /* The first and subsequent entries are handled slightly differently */
+              if (bootstrapClassPath)
+                {
+                  char *oldPath = bootstrapClassPath;
+                  bootstrapClassPath =
+                    concat (PORTLIB, bootstrapClassPath, cpSeparator,
+                            bootDirectory, property->value, NULL);
+                  hymem_free_memory (oldPath);
+                }
+              else
+                {
+                  bootstrapClassPath =
+                    concat (PORTLIB, "", bootDirectory, property->value,
+                            NULL);
+                }
+
+              if (!bootstrapClassPath)
+                {
+                  returnCode = JNI_ENOMEM;      /* bail - memory allocate must have failed */
+                  break;
+                }
+            }
+
+          /* Advance to next element */
+          property = (props_file_entry *) pool_nextDo (&poolState);
+        }
+    }
+
+cleanup:
+
+  /* Free the properties pool (remember to free structure elements) */
+  if (properties)
+    {
+      pool_state poolState;
+      props_file_entry *property = pool_startDo (properties, &poolState);
+
+      while (property)
+        {
+          if (property->key)
+            {
+              hymem_free_memory (property->key);
+            }
+          if (property->value)
+            {
+              hymem_free_memory (property->value);
+            }
+          property = (props_file_entry *) pool_nextDo (&poolState);
+        }
+      pool_kill (properties);
+    }
+
+  /* Commit the full bootstrap class path into the VMI */
+  if (bootstrapClassPath)
+    {
+      vmiError rcSetProperty = (*vmInterface)->SetSystemProperty (vmInterface,
+                                                                  "com.ibm.oti.system.class.path",
+                                                                  bootstrapClassPath);
+      if (VMI_ERROR_NONE != rcSetProperty)
+        {
+          returnCode = JNI_ERR;
+        }
+      hymem_free_memory (bootstrapClassPath);
+    }
+
+  return returnCode;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,84 @@
+# Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Makefile for module 'archive'
+#
+
+APPVER=4.0
+TARGETOS=WIN95
+_WIN32_IE=0x0500
+SEHMAP = TRUE
+!include <win32.mak>
+
+DLLFILENAME=hyarchive.dll# declaration
+
+DLLNAME=..\hyarchive.dll# declaration
+
+LIBNAME=hyarchive# declaration
+
+LIBPATH=..\lib\# declaration
+
+.c.obj:
+	$(cc) -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 $(cflags) -D_MT -D_DLL -MD -D_WINSOCKAPI_ -DWIN32 -Ogityb1 -Gs -GF -Zm400 -WX -Zi  /I..\include /I..\archive /I..\common /I..\zlib /I..\zip /I..\fdlibm  $(VMDEBUG) $*.c
+
+.cpp.obj:
+	$(cc) -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 $(cflags) -D_MT -D_DLL -MD -D_WINSOCKAPI_ -DWIN32 -Ogityb1 -Gs -GF -Zm400 -WX -Zi  /I..\include /I..\archive /I..\common /I..\zlib /I..\zip /I..\fdlibm  $(VMDEBUG) $*.cpp
+
+.asm.obj:
+	ml /c /Cp /W3 /nologo /coff /Zm /Zd /Zi /Gd  $(VMASMDEBUG) -DWIN32  $<
+
+.rc.res:
+	rc -I..\include $<
+
+BUILDFILES1 = archive_copyright.obj jclcrc32.obj zip.obj adler32.obj inflater.obj
+BUILDFILES2 = jarfile.obj deflater.obj archiveglob.obj
+
+VIRTFILES1 = hyarchive.res
+
+SYSLIBFILES1 = ws2_32.lib Iphlpapi.lib
+
+MDLLIBFILES1 = ..\lib\hycommon.lib ..\lib\hysig.lib ..\lib\hyzip.lib ..\lib\hyzlib.lib
+MDLLIBFILES2 = ..\lib\hypool.lib ..\lib\hyfdlibm.lib ..\lib\hythr.lib ..\lib\vmi.lib
+
+all: \
+	 ..\lib\$(LIBNAME).lib $(DLLNAME)
+
+BUILDLIB: $(LIBPATH)$(LIBNAME).lib
+
+$(LIBPATH)$(LIBNAME).lib:\
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+	$(implib) /nologo -subsystem:windows -out:$(LIBPATH)$(LIBNAME).lib -def:$(LIBNAME).def -machine:$(CPU) \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+
+
+$(DLLNAME): $(LIBPATH)$(LIBNAME).lib \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+	link $(VMLINK) /debug /opt:icf /opt:ref /INCREMENTAL:NO /NOLOGO -entry:_DllMainCRTStartup@12 -dll /BASE:0x13100000 -machine:$(CPU) \
+	-subsystem:windows -out:$(DLLNAME) -map:$(LIBNAME).map  \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) \
+	$(SYSLIBFILES1)  \
+	kernel32.lib  ws2_32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib  $(LIBPATH)$(LIBNAME).exp
+	cd ..
+	cd archive
+	
+clean:
+	-del *.map
+	-del *.obj
+	-del *.res
+	-del *.pdb
+	-del ..\lib\$(LIBNAME).lib
+	-del ..\lib\$(LIBNAME).exp
+	-del ..\$(LIBNAME).pdb
+	-del $(DLLNAME)

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,447 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "iohelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+#include "zip.h"
+
+void zfree PROTOTYPE ((void *opaque, void *address));
+void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
+
+void throwNewOutOfMemoryError (JNIEnv * env, char *message);
+
+/**
+  * Throw java.lang.InternalError
+  */
+void
+throwNewInternalError (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/lang/InternalError");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+/**
+  * Throw java.util.zip.ZipException with the message provided
+  */
+void
+throwJavaZIOException (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/util/zip/ZipException");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+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),
+                        ((jlong) jclZipFile));
+  return 0;
+}
+
+jobject JNICALL
+Java_java_util_zip_ZipFile_getEntryImpl (JNIEnv * env, jobject recv,
+                                         jlong zipPointer, jstring entryName)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  I_32 retval;
+  HyZipFile *zipFile;
+  HyZipEntry zipEntry;
+  jobject java_ZipEntry, extra;
+  jclass entryClass;
+  jmethodID mid;
+  const char *entryCopy;
+
+  if ((JCLZipFile *) zipPointer == (void *) -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return NULL;
+    }
+
+  zipFile = &(((JCLZipFile *) zipPointer)->hyZipFile);
+  entryCopy = (*env)->GetStringUTFChars (env, entryName, NULL);
+  if (entryCopy == NULL)
+    return (jobject) NULL;
+
+  zip_initZipEntry (PORTLIB, &zipEntry);
+  retval = zip_getZipEntry (PORTLIB, zipFile, &zipEntry, entryCopy, TRUE);
+  (*env)->ReleaseStringUTFChars (env, entryName, entryCopy);
+  if (retval)
+    {
+      zip_freeZipEntry (PORTLIB, &zipEntry);
+      return (jobject) NULL;
+    }
+
+  extra = NULL;
+  if (zipEntry.extraFieldLength > 0)
+    {
+      zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL,
+                                 zipEntry.extraFieldLength);
+      if (zipEntry.extraField == NULL)
+        {
+          zip_freeZipEntry (PORTLIB, &zipEntry);
+          return (jobject) NULL;
+        }
+      extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength));
+      if (((*env)->ExceptionCheck (env)))
+        {
+          zip_freeZipEntry (PORTLIB, &zipEntry);
+          return (jobject) NULL;
+        }
+      ((*env)->
+       SetByteArrayRegion (env, extra, 0, zipEntry.extraFieldLength,
+                           zipEntry.extraField));
+    }
+
+  entryClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+  mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+  /* Build a new ZipEntry from the C struct */
+  java_ZipEntry = ((*env)->NewObject (env, entryClass, mid, entryName, NULL,
+                                      extra,
+                                      (jlong) zipEntry.lastModTime,
+                                      (jlong) zipEntry.uncompressedSize,
+                                      (jlong) zipEntry.compressedSize,
+                                      (jlong) zipEntry.crc32,
+                                      zipEntry.compressionMethod,
+                                      (jlong) zipEntry.lastModDate,
+                                      (jlong) zipEntry.dataPointer));
+  zip_freeZipEntry (PORTLIB, &zipEntry);
+  return java_ZipEntry;
+}
+
+void JNICALL
+Java_java_util_zip_ZipFile_closeZipImpl (JNIEnv * env, jobject recv)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  I_32 retval = 0;
+  JCLZipFile *jclZipFile;
+  jfieldID descriptorFID =
+    JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_descriptor);
+
+  jclZipFile = (JCLZipFile *) (*env)->GetLongField (env, recv, descriptorFID);
+  if (jclZipFile != (void *) -1)
+    {
+      retval =
+        zip_closeZipFile (privatePortLibrary, &(jclZipFile->hyZipFile));
+      (*env)->SetLongField (env, recv, descriptorFID, -1);
+
+      /* Free the zip struct */
+      if (jclZipFile->last != NULL)
+        jclZipFile->last->next = jclZipFile->next;
+      if (jclZipFile->next != NULL)
+        jclZipFile->next->last = jclZipFile->last;
+
+      jclmem_free_memory (env, jclZipFile);
+      if (retval)
+        {
+          throwJavaZIOException (env, "");
+          return;
+        }
+    }
+}
+
+/**
+  * Throw java.lang.IllegalStateException
+  */
+void
+throwNewIllegalStateException (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalStateException");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+/**
+  * Throw java.lang.IllegalArgumentException
+  */
+void
+throwNewIllegalArgumentException (JNIEnv * env, char *message)
+{
+  jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
+  if (0 == exceptionClass) { 
+    /* Just return if we can't load the exception class. */
+    return;
+    }
+  (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+void JNICALL
+Java_java_util_zip_ZipFile_ntvinit (JNIEnv * env, jclass cls)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jmethodID mid;
+  jfieldID descriptorFID;
+  jclass javaClass;
+  JCLZipFileLink *zipfileHandles;
+
+  javaClass = (*env)->FindClass (env, "java/util/zip/ZipEntry");
+  javaClass = (*env)->NewWeakGlobalRef (env, javaClass);
+  if (!javaClass)
+    return;
+  mid =
+    ((*env)->
+     GetMethodID (env, javaClass, "<init>",
+                  "(Ljava/lang/String;Ljava/lang/String;[BJJJJIJJ)V"));
+  if (!mid)
+    return;
+  JCL_CACHE_SET (env, CLS_java_util_zip_ZipEntry, javaClass);
+  JCL_CACHE_SET (env, MID_java_util_zip_ZipEntry_init, mid);
+
+  descriptorFID = (*env)->GetFieldID (env, cls, "descriptor", "J");
+  if (!descriptorFID)
+    return;
+  JCL_CACHE_SET (env, FID_java_util_zip_ZipFile_descriptor, descriptorFID);
+
+  javaClass = (*env)->FindClass (env, "java/util/zip/ZipFile$ZFEnum");
+  if (!javaClass)
+    return;
+  descriptorFID =
+    (*env)->GetFieldID (env, javaClass, "nextEntryPointer", "J");
+  if (!descriptorFID)
+    return;
+  JCL_CACHE_SET (env, FID_java_util_zip_ZipFile_nextEntryPointer,
+                 descriptorFID);
+
+  zipfileHandles = jclmem_allocate_memory (env, sizeof (JCLZipFileLink));
+  if (!zipfileHandles)
+    return;
+  zipfileHandles->last = NULL;
+  zipfileHandles->next = NULL;
+  JCL_CACHE_SET (env, zipfile_handles, zipfileHandles);
+}
+
+jlong JNICALL
+Java_java_util_zip_ZipFile_00024ZFEnum_resetZip (JNIEnv * env, jobject recv,
+                                                 jlong descriptor)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  IDATA nextEntryPointer;
+
+  if ((JCLZipFile *) descriptor == (void *) -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return 0;
+    }
+  zip_resetZipFile (privatePortLibrary,
+                    &(((JCLZipFile *) descriptor)->hyZipFile),
+                    &nextEntryPointer);
+  return nextEntryPointer;
+}
+
+jobject JNICALL
+Java_java_util_zip_ZipFile_00024ZFEnum_getNextEntry (JNIEnv * env,
+                                                     jobject recv,
+                                                     jlong descriptor,
+                                                     jlong nextEntry)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  I_32 retval;
+  HyZipFile *zipFile;
+  HyZipEntry zipEntry;
+  jobject java_ZipEntry, extra;
+  jclass javaClass;
+  jmethodID mid;
+  jstring entryName = NULL;
+  IDATA nextEntryPointer;
+
+  if ((JCLZipFile *) descriptor == (void *) -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return NULL;
+    }
+  zipFile = &(((JCLZipFile *) descriptor)->hyZipFile);
+  zip_initZipEntry (PORTLIB, &zipEntry);
+
+  nextEntryPointer = (IDATA) nextEntry;
+  retval =
+    zip_getNextZipEntry (PORTLIB, zipFile, &zipEntry, &nextEntryPointer);
+  if (retval)
+    {
+      if (retval != ZIP_ERR_NO_MORE_ENTRIES)
+        {
+          char buf[40];
+          sprintf (buf, "Error %d getting next zip entry", retval);
+          throwNewInternalError (env, buf);
+        }
+      return (jobject) NULL;
+    }
+
+  /* Build a new ZipEntry from the C struct */
+  entryName = ((*env)->NewStringUTF (env, zipEntry.filename));
+
+  if (((*env)->ExceptionCheck (env)))
+    return NULL;
+
+  extra = NULL;
+  if (zipEntry.extraFieldLength > 0)
+    {
+      zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL,
+                                 zipEntry.extraFieldLength);
+      extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength));
+      if (((*env)->ExceptionCheck (env)))
+        {
+          /* free the extraField entry */
+          zip_freeZipEntry (PORTLIB, &zipEntry);
+          return NULL;
+        }
+      ((*env)->
+       SetByteArrayRegion (env, extra, 0, zipEntry.extraFieldLength,
+                           zipEntry.extraField));
+      jclmem_free_memory (env, zipEntry.extraField);
+      zipEntry.extraField = NULL;
+    }
+
+  javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+  mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+  java_ZipEntry = ((*env)->NewObject (env, javaClass, mid, entryName, NULL,     /* comment */
+                                      extra,
+                                      (jlong) zipEntry.lastModTime,
+                                      (jlong) zipEntry.uncompressedSize,
+                                      (jlong) zipEntry.compressedSize,
+                                      (jlong) zipEntry.crc32,
+                                      zipEntry.compressionMethod,
+                                      (jlong) zipEntry.lastModDate,
+                                      (jlong) zipEntry.dataPointer));
+  zip_freeZipEntry (PORTLIB, &zipEntry);
+  (*env)->SetLongField (env, recv,
+                        JCL_CACHE_GET (env,
+                                       FID_java_util_zip_ZipFile_nextEntryPointer),
+                        nextEntryPointer);
+  return java_ZipEntry;
+}
+
+jbyteArray JNICALL
+Java_java_util_zip_ZipFile_inflateEntryImpl2 (JNIEnv * env, jobject recv,
+                                              jlong zipPointer,
+                                              jstring entryName)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  I_32 retval;
+  HyZipFile *zipFile;
+  HyZipEntry zipEntry;
+  const char *entryCopy;
+  jbyteArray buf;
+
+  /* Build the zipFile */
+  if ((JCLZipFile *) zipPointer == (void *) -1)
+    {
+      throwNewIllegalStateException (env, "");
+      return NULL;
+    }
+  zipFile = &(((JCLZipFile *) zipPointer)->hyZipFile);
+  entryCopy = (*env)->GetStringUTFChars (env, entryName, NULL);
+  if (entryCopy == NULL)
+    return NULL;
+
+  zip_initZipEntry (privatePortLibrary, &zipEntry);
+  retval =
+    zip_getZipEntry (privatePortLibrary, zipFile, &zipEntry, entryCopy, TRUE);
+  (*env)->ReleaseStringUTFChars (env, entryName, entryCopy);
+  if (retval)
+    {
+      zip_freeZipEntry (privatePortLibrary, &zipEntry);
+      if (retval == ZIP_ERR_OUT_OF_MEMORY)
+        throwNewOutOfMemoryError (env, "");
+      return NULL;
+    }
+
+  buf = (*env)->NewByteArray (env, zipEntry.uncompressedSize);
+  if (!buf)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return NULL;
+    }
+
+  retval =
+    zip_getZipEntryData (privatePortLibrary, zipFile, &zipEntry, NULL,
+                         zipEntry.uncompressedSize);
+  if (retval == 0)
+    (*env)->SetByteArrayRegion (env, buf, 0, zipEntry.uncompressedSize,
+                                zipEntry.data);
+  zip_freeZipEntry (privatePortLibrary, &zipEntry);
+  if (!retval)
+    return buf;
+
+  if (retval == ZIP_ERR_OUT_OF_MEMORY)
+    throwNewOutOfMemoryError (env, "");
+  else
+    throwJavaZIOException (env, "");
+
+  return NULL;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/archive/zip.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(zip_h)
+#define zip_h
+
+#include "zipsup.h"
+
+typedef struct JCLZipFile
+{
+  struct JCLZipFile *last;
+  struct JCLZipFile *next;
+  HyZipFile hyZipFile;
+} JCLZipFile;
+
+/* Fake JCLZipFile entry. last, next must be in the same position as JCLZipFile */
+typedef struct JCLZipFileLink
+{
+  JCLZipFile *last;
+  JCLZipFile *next;
+} JCLZipFileLink;
+
+#endif /* zip_h */



Mime
View raw message