aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util/zip/natInflater.cc
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>1999-05-18 15:33:03 +0000
committerTom Tromey <tromey@gcc.gnu.org>1999-05-18 15:33:03 +0000
commit0ffac8322f8825c0d696d9c700b0d0f1a395d11a (patch)
treec538fe74824c64ba74944a357c354f0c77e93be5 /libjava/java/util/zip/natInflater.cc
parent5a9e5c6fb6c140bd80a2986f1d537a250a62ea59 (diff)
downloadgcc-0ffac8322f8825c0d696d9c700b0d0f1a395d11a.zip
gcc-0ffac8322f8825c0d696d9c700b0d0f1a395d11a.tar.gz
gcc-0ffac8322f8825c0d696d9c700b0d0f1a395d11a.tar.bz2
ZipOutputStream.java (level): Initial value is Deflater.DEFAULT_COMPRESSION.
* java/util/zip/ZipOutputStream.java (level): Initial value is Deflater.DEFAULT_COMPRESSION. (close): New method. (closeEntry): Likewise. (finish): Likewise. (put_version): Likewise. (write_entry): Likewise. (put2, put4): Now return `int'. (comment): Default to empty string. (bytes_written): New instance variable. (chain): Likewise. * java/util/zip/ZipEntry.java (setComment): Limit length of comment string. (setCrc): Check CRC validity. (setExtra): Check argument validity. (setMethod): Likewise. (setSize): Likewise. (ZipEntry): Likewise. * include/javaprims.h: Updated namespace declarations. * Makefile.in: Rebuilt. * Makefile.am (ordinary_java_source_files): Mention new files. (nat_source_files): Likewise. * java/util/zip/ZipFile.java (readu2): Throw ZipException, not EOFException. (read4): Likewise. (getInputStream): Handle compressed entries. * java/util/zip/GZIPOutputStream.java: New file. * java/util/zip/GZIPInputStream.java: New file. * java/util/zip/DataFormatException.java: New file. * java/util/zip/CheckedInputStream.java: New file. * java/util/zip/CheckedOutputStream.java: New file. * java/util/zip/InflaterInputStream.java: Implemented. * java/util/zip/natInflater.cc: New file. * java/util/zip/Deflater.java: Implemented. * java/util/zip/natDeflater.cc: New file. * java/util/zip/DeflaterOutputStream.java: Implemented. * java/util/zip/ZipInputStream.java (closeZipEntry): Throw ZipException, not IOException. * java/util/zip/ZipFile.java (readDirectory): Throw ZipException, not IOException. From-SVN: r26996
Diffstat (limited to 'libjava/java/util/zip/natInflater.cc')
-rw-r--r--libjava/java/util/zip/natInflater.cc202
1 files changed, 202 insertions, 0 deletions
diff --git a/libjava/java/util/zip/natInflater.cc b/libjava/java/util/zip/natInflater.cc
new file mode 100644
index 0000000..b33ab50
--- /dev/null
+++ b/libjava/java/util/zip/natInflater.cc
@@ -0,0 +1,202 @@
+// natInflater.cc - Implementation of Inflater native methods.
+
+/* Copyright (C) 1999 Cygnus Solutions
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+// Written by Tom Tromey <tromey@cygnus.com>
+
+#include <config.h>
+
+#include <zlib.h>
+
+#include <cni.h>
+#include <jvm.h>
+
+#include <java/util/zip/Inflater.h>
+#include <java/util/zip/DataFormatException.h>
+
+#include <java/lang/InternalError.h>
+#include <java/lang/NullPointerException.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
+#include <java/lang/OutOfMemoryError.h>
+
+
+
+// A couple of helper functions used to interface with zlib's
+// allocation.
+
+void *
+_Jv_ZMalloc (void *, uInt nitems, uInt size)
+{
+ return _Jv_Malloc (nitems * size);
+}
+
+void
+_Jv_ZFree (void *, void *addr)
+{
+ _Jv_Free (addr);
+}
+
+
+
+void
+java::util::zip::Inflater::end ()
+{
+ JvSynchronize sync (this);
+ // Just ignore errors.
+ inflateEnd ((z_streamp) zstream);
+ _Jv_Free (zstream);
+ zstream = NULL;
+}
+
+jint
+java::util::zip::Inflater::getAdler ()
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+ return s->adler;
+}
+
+jint
+java::util::zip::Inflater::getRemaining ()
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+ return s->avail_in - last_input_count;
+}
+
+jint
+java::util::zip::Inflater::getTotalIn ()
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+ return s->total_in;
+}
+
+jint
+java::util::zip::Inflater::getTotalOut ()
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+ return s->total_out;
+}
+
+jint
+java::util::zip::Inflater::inflate (jbyteArray buf, jint off, jint len)
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+
+ if (! buf)
+ _Jv_Throw (new java::lang::NullPointerException);
+ if (off < 0 || len < 0 || off + len > buf->length)
+ _Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
+
+ s->next_out = (Bytef *) (elements (buf) + off);
+ s->avail_out = len;
+
+ switch (::inflate (s, Z_SYNC_FLUSH))
+ {
+ case Z_STREAM_END:
+ is_finished = true;
+ if (s->avail_out == len)
+ return -1;
+ break;
+
+ case Z_NEED_DICT:
+ dict_needed = true;
+ break;
+
+ case Z_DATA_ERROR:
+ _Jv_Throw (new java::util::zip::DataFormatException);
+ break;
+
+ case Z_MEM_ERROR:
+ _Jv_Throw (new java::lang::OutOfMemoryError);
+ break;
+
+ case Z_BUF_ERROR:
+ // FIXME?
+ _Jv_Throw (new java::lang::InternalError);
+ break;
+
+ case Z_OK:
+ break;
+ }
+
+ return len - s->avail_out;
+}
+
+void
+java::util::zip::Inflater::reset ()
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+ // Just ignore errors.
+ inflateReset (s);
+}
+
+void
+java::util::zip::Inflater::setDictionary (jbyteArray buf, jint off, jint len)
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+
+ if (! buf)
+ _Jv_Throw (new java::lang::NullPointerException);
+ if (off < 0 || len < 0 || off + len > buf->length)
+ _Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
+
+ // Ignore errors.
+ inflateSetDictionary (s, (Bytef *) (elements (buf) + off), len);
+ dict_needed = false;
+}
+
+void
+java::util::zip::Inflater::setInput (jbyteArray buf, jint off, jint len)
+{
+ JvSynchronize sync (this);
+ z_streamp s = (z_streamp) zstream;
+
+ if (! buf)
+ _Jv_Throw (new java::lang::NullPointerException);
+ if (off < 0 || len < 0 || off + len > buf->length)
+ _Jv_Throw (new java::lang::ArrayIndexOutOfBoundsException);
+
+ last_input_count = len;
+ s->next_in = (Bytef *) (elements (buf) + off);
+ s->avail_in = len;
+}
+
+void
+java::util::zip::Inflater::init (jboolean no_header)
+{
+ z_stream_s *stream = (z_stream_s *) _Jv_Malloc (sizeof (z_stream_s));
+ stream->next_in = Z_NULL;
+ stream->avail_in = 0;
+ stream->zalloc = _Jv_ZMalloc;
+ stream->zfree = _Jv_ZFree;
+ stream->opaque = NULL;
+
+ // Handle NO_HEADER using undocumented zlib feature.
+ int wbits = MAX_WBITS;
+ if (no_header)
+ wbits = - wbits;
+
+ if (inflateInit2 (stream, wbits) != Z_OK)
+ {
+ jstring msg = NULL;
+ if (stream->msg != NULL)
+ msg = JvNewStringLatin1 (stream->msg);
+ _Jv_Throw (new java::lang::InternalError (msg));
+ }
+
+ zstream = reinterpret_cast<gnu::gcj::RawData *> (stream);
+ is_finished = false;
+ dict_needed = false;
+}