diff options
Diffstat (limited to 'libjava/java/util/zip')
25 files changed, 1912 insertions, 0 deletions
diff --git a/libjava/java/util/zip/Adler32.h b/libjava/java/util/zip/Adler32.h new file mode 100644 index 000000000..ebd8e33cf --- /dev/null +++ b/libjava/java/util/zip/Adler32.h @@ -0,0 +1,30 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_Adler32__ +#define __java_util_zip_Adler32__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::util::zip::Adler32 : public ::java::lang::Object +{ + +public: + Adler32(); + virtual void reset(); + virtual void update(jint); + virtual void update(JArray< jbyte > *); + virtual void update(JArray< jbyte > *, jint, jint); + virtual jlong getValue(); +private: + static const jint BASE = 65521; + jint __attribute__((aligned(__alignof__( ::java::lang::Object)))) checksum; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_Adler32__ diff --git a/libjava/java/util/zip/CRC32.h b/libjava/java/util/zip/CRC32.h new file mode 100644 index 000000000..af515fc99 --- /dev/null +++ b/libjava/java/util/zip/CRC32.h @@ -0,0 +1,33 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_CRC32__ +#define __java_util_zip_CRC32__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::util::zip::CRC32 : public ::java::lang::Object +{ + +public: + CRC32(); +private: + static JArray< jint > * make_crc_table(); +public: + virtual jlong getValue(); + virtual void reset(); + virtual void update(jint); + virtual void update(JArray< jbyte > *, jint, jint); + virtual void update(JArray< jbyte > *); +private: + jint __attribute__((aligned(__alignof__( ::java::lang::Object)))) crc; + static JArray< jint > * crc_table; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_CRC32__ diff --git a/libjava/java/util/zip/CheckedInputStream.h b/libjava/java/util/zip/CheckedInputStream.h new file mode 100644 index 000000000..d9e80abe9 --- /dev/null +++ b/libjava/java/util/zip/CheckedInputStream.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_CheckedInputStream__ +#define __java_util_zip_CheckedInputStream__ + +#pragma interface + +#include <java/io/FilterInputStream.h> +#include <gcj/array.h> + + +class java::util::zip::CheckedInputStream : public ::java::io::FilterInputStream +{ + +public: + CheckedInputStream(::java::io::InputStream *, ::java::util::zip::Checksum *); + virtual ::java::util::zip::Checksum * getChecksum(); + virtual jint read(); + virtual jint read(JArray< jbyte > *, jint, jint); + virtual jlong skip(jlong); +private: + ::java::util::zip::Checksum * __attribute__((aligned(__alignof__( ::java::io::FilterInputStream)))) sum; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_CheckedInputStream__ diff --git a/libjava/java/util/zip/CheckedOutputStream.h b/libjava/java/util/zip/CheckedOutputStream.h new file mode 100644 index 000000000..5cf53c9f2 --- /dev/null +++ b/libjava/java/util/zip/CheckedOutputStream.h @@ -0,0 +1,27 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_CheckedOutputStream__ +#define __java_util_zip_CheckedOutputStream__ + +#pragma interface + +#include <java/io/FilterOutputStream.h> +#include <gcj/array.h> + + +class java::util::zip::CheckedOutputStream : public ::java::io::FilterOutputStream +{ + +public: + CheckedOutputStream(::java::io::OutputStream *, ::java::util::zip::Checksum *); + virtual ::java::util::zip::Checksum * getChecksum(); + virtual void write(jint); + virtual void write(JArray< jbyte > *, jint, jint); +private: + ::java::util::zip::Checksum * __attribute__((aligned(__alignof__( ::java::io::FilterOutputStream)))) sum; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_CheckedOutputStream__ diff --git a/libjava/java/util/zip/Checksum.h b/libjava/java/util/zip/Checksum.h new file mode 100644 index 000000000..66ab907c8 --- /dev/null +++ b/libjava/java/util/zip/Checksum.h @@ -0,0 +1,24 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_Checksum__ +#define __java_util_zip_Checksum__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::util::zip::Checksum : public ::java::lang::Object +{ + +public: + virtual jlong getValue() = 0; + virtual void reset() = 0; + virtual void update(jint) = 0; + virtual void update(JArray< jbyte > *, jint, jint) = 0; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_util_zip_Checksum__ diff --git a/libjava/java/util/zip/DataFormatException.h b/libjava/java/util/zip/DataFormatException.h new file mode 100644 index 000000000..5ebfbcf4b --- /dev/null +++ b/libjava/java/util/zip/DataFormatException.h @@ -0,0 +1,23 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_DataFormatException__ +#define __java_util_zip_DataFormatException__ + +#pragma interface + +#include <java/lang/Exception.h> + +class java::util::zip::DataFormatException : public ::java::lang::Exception +{ + +public: + DataFormatException(); + DataFormatException(::java::lang::String *); +private: + static const jlong serialVersionUID = 2219632870893641452LL; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_DataFormatException__ diff --git a/libjava/java/util/zip/Deflater.h b/libjava/java/util/zip/Deflater.h new file mode 100644 index 000000000..61d21899f --- /dev/null +++ b/libjava/java/util/zip/Deflater.h @@ -0,0 +1,76 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_Deflater__ +#define __java_util_zip_Deflater__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + } + } +} + +class java::util::zip::Deflater : public ::java::lang::Object +{ + +public: + Deflater(); + Deflater(jint); + Deflater(jint, jboolean); +private: + void init(jint, jboolean); + void update(); +public: + virtual void reset(); + virtual void end(); + virtual jint getAdler(); + virtual jint getTotalIn(); + virtual jlong getBytesRead(); + virtual jint getTotalOut(); + virtual jlong getBytesWritten(); +public: // actually protected + virtual void finalize(); +public: + virtual void finish(); + virtual jboolean finished(); + virtual jboolean needsInput(); + virtual void setInput(JArray< jbyte > *); + virtual void setInput(JArray< jbyte > *, jint, jint); + virtual void setLevel(jint); + virtual void setStrategy(jint); + virtual jint deflate(JArray< jbyte > *); + virtual jint deflate(JArray< jbyte > *, jint, jint); + virtual void setDictionary(JArray< jbyte > *); + virtual void setDictionary(JArray< jbyte > *, jint, jint); +public: // actually package-private + virtual void flush(); +public: + static const jint BEST_COMPRESSION = 9; + static const jint BEST_SPEED = 1; + static const jint DEFAULT_COMPRESSION = -1; + static const jint NO_COMPRESSION = 0; + static const jint DEFAULT_STRATEGY = 0; + static const jint FILTERED = 1; + static const jint HUFFMAN_ONLY = 2; + static const jint DEFLATED = 8; +private: + jint __attribute__((aligned(__alignof__( ::java::lang::Object)))) level; + jint strategy; + ::gnu::gcj::RawData * zstream; + jboolean is_finished; + jint flush_flag; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_Deflater__ diff --git a/libjava/java/util/zip/Deflater.java b/libjava/java/util/zip/Deflater.java new file mode 100644 index 000000000..47383ab4b --- /dev/null +++ b/libjava/java/util/zip/Deflater.java @@ -0,0 +1,354 @@ +/* Deflater.java - Compress a data stream + Copyright (C) 1999, 2000, 2001, 2004, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.util.zip; + +import gnu.gcj.RawData; + +/** + * This is the Deflater class. The deflater class compresses input + * with the deflate algorithm described in RFC 1951. It has several + * compression levels and three different strategies described below. + * + * This class is <i>not</i> thread safe. This is inherent in the API, due + * to the split of deflate and setInput. + * + * @author Jochen Hoenicke + * @author Tom Tromey + */ +public class Deflater +{ + /** + * The best and slowest compression level. This tries to find very + * long and distant string repetitions. + */ + public static final int BEST_COMPRESSION = 9; + /** + * The worst but fastest compression level. + */ + public static final int BEST_SPEED = 1; + /** + * The default compression level. + */ + public static final int DEFAULT_COMPRESSION = -1; + /** + * This level won't compress at all but output uncompressed blocks. + */ + public static final int NO_COMPRESSION = 0; + + /** + * The default strategy. + */ + public static final int DEFAULT_STRATEGY = 0; + /** + * This strategy will only allow longer string repetitions. It is + * useful for random data with a small character set. + */ + public static final int FILTERED = 1; + + /** + * This strategy will not look for string repetitions at all. It + * only encodes with Huffman trees (which means, that more common + * characters get a smaller encoding. + */ + public static final int HUFFMAN_ONLY = 2; + + /** + * The compression method. This is the only method supported so far. + * There is no need to use this constant at all. + */ + public static final int DEFLATED = 8; + + /** Compression level. */ + private int level; + + /** Compression strategy. */ + private int strategy; + + /** The zlib stream. */ + private RawData zstream; + + /** True if finished. */ + private boolean is_finished; + + /** `Flush' flag to pass to next call to deflate. */ + private int flush_flag; + + /** + * Creates a new deflater with default compression level. + */ + public Deflater() + { + this(DEFAULT_COMPRESSION, false); + } + + /** + * Creates a new deflater with given compression level. + * @param lvl the compression level, a value between NO_COMPRESSION + * and BEST_COMPRESSION, or DEFAULT_COMPRESSION. + * @exception IllegalArgumentException if lvl is out of range. + */ + public Deflater(int lvl) + { + this(lvl, false); + } + + /** + * Creates a new deflater with given compression level. + * @param lvl the compression level, a value between NO_COMPRESSION + * and BEST_COMPRESSION. + * @param nowrap true, iff we should suppress the deflate header at the + * beginning and the adler checksum at the end of the output. This is + * useful for the GZIP format. + * @exception IllegalArgumentException if lvl is out of range. + */ + public Deflater(int lvl, boolean noHeader) + { + this.strategy = DEFAULT_STRATEGY; + init(lvl, noHeader); + setLevel(lvl); + } + + private native void init(int level, boolean noHeader); + + private native void update(); + + /** + * Resets the deflater. The deflater acts afterwards as if it was + * just created with the same compression level and strategy as it + * had before. + */ + public native void reset(); + + /** + * Frees all objects allocated by the compressor. There's no + * reason to call this, since you can just rely on garbage + * collection. Exists only for compatibility against Sun's JDK, + * where the compressor allocates native memory. + * If you call any method (even reset) afterwards the behaviour is + * <i>undefined</i>. + * @deprecated Just clear all references to deflater instead. + */ + public native void end(); + + /** + * Gets the current adler checksum of the data that was processed so + * far. + */ + public native int getAdler(); + + /** + * Gets the number of input bytes processed so far. + */ + @Deprecated + public int getTotalIn() + { + return (int) getBytesRead(); + } + + /** + * Gets the number of input bytes processed so far. + * @since 1.5 + */ + public native long getBytesRead(); + + /** + * Gets the number of output bytes so far. + */ + @Deprecated + public int getTotalOut() + { + return (int) getBytesWritten(); + } + + /** + * Gets the number of output bytes so far. + * @since 1.5 + */ + public native long getBytesWritten(); + + /** + * Finalizes this object. + */ + protected void finalize() + { + end(); + } + + /** + * Finishes the deflater with the current input block. It is an error + * to give more input after this method was called. This method must + * be called to force all bytes to be flushed. + */ + public native void finish(); + + /** + * Returns true iff the stream was finished and no more output bytes + * are available. + */ + public synchronized boolean finished() + { + return is_finished; + } + + /** + * Returns true, if the input buffer is empty. + * You should then call setInput(). <br> + * + * <em>NOTE</em>: This method can also return true when the stream + * was finished. + */ + public native boolean needsInput(); + + /** + * Sets the data which should be compressed next. This should be only + * called when needsInput indicates that more input is needed. + * If you call setInput when needsInput() returns false, the + * previous input that is still pending will be thrown away. + * The given byte array should not be changed, before needsInput() returns + * true again. + * This call is equivalent to <code>setInput(input, 0, input.length)</code>. + * @param input the buffer containing the input data. + * @exception IllegalStateException if the buffer was finished() or ended(). + */ + public void setInput(byte[] input) + { + setInput(input, 0, input.length); + } + + /** + * Sets the data which should be compressed next. This should be + * only called when needsInput indicates that more input is needed. + * The given byte array should not be changed, before needsInput() returns + * true again. + * @param input the buffer containing the input data. + * @param off the start of the data. + * @param len the length of the data. + * @exception IllegalStateException if the buffer was finished() or ended() + * or if previous input is still pending. + */ + public native void setInput(byte[] input, int off, int len); + + /** + * Sets the compression level. There is no guarantee of the exact + * position of the change, but if you call this when needsInput is + * true the change of compression level will occur somewhere near + * before the end of the so far given input. + * @param lvl the new compression level. + */ + public synchronized void setLevel(int lvl) + { + if (lvl != -1 && (lvl < 0 || lvl > 9)) + throw new IllegalArgumentException(); + level = (lvl == -1) ? 6 : lvl; + update(); + } + + /** + * Sets the compression strategy. Strategy is one of + * DEFAULT_STRATEGY, HUFFMAN_ONLY and FILTERED. For the exact + * position where the strategy is changed, the same as for + * setLevel() applies. + * @param stgy the new compression strategy. + */ + public synchronized void setStrategy(int stgy) + { + if (stgy != DEFAULT_STRATEGY && stgy != FILTERED + && stgy != HUFFMAN_ONLY) + throw new IllegalArgumentException(); + strategy = stgy; + update(); + } + + /** + * Deflates the current input block to the given array. It returns + * the number of bytes compressed, or 0 if either + * needsInput() or finished() returns true or length is zero. + * @param output the buffer where to write the compressed data. + */ + public int deflate(byte[] output) + { + return deflate(output, 0, output.length); + } + + /** + * Deflates the current input block to the given array. It returns + * the number of bytes compressed, or 0 if either + * needsInput() or finished() returns true or length is zero. + * @param output the buffer where to write the compressed data. + * @param offset the offset into the output array. + * @param length the maximum number of bytes that may be written. + * @exception IllegalStateException if end() was called. + * @exception IndexOutOfBoundsException if offset and/or length + * don't match the array length. + */ + public native int deflate(byte[] output, int off, int len); + + /** + * Sets the dictionary which should be used in the deflate process. + * This call is equivalent to <code>setDictionary(dict, 0, + * dict.length)</code>. + * @param dict the dictionary. + * @exception IllegalStateException if setInput () or deflate () + * were already called or another dictionary was already set. + */ + public void setDictionary(byte[] dict) + { + setDictionary(dict, 0, dict.length); + } + + /** + * Sets the dictionary which should be used in the deflate process. + * The dictionary should be a byte array containing strings that are + * likely to occur in the data which should be compressed. The + * dictionary is not stored in the compressed output, only a + * checksum. To decompress the output you need to supply the same + * dictionary again. + * @param dict the dictionary. + * @param offset an offset into the dictionary. + * @param length the length of the dictionary. + * @exception IllegalStateException if setInput () or deflate () were + * already called or another dictionary was already set. + */ + public native void setDictionary(byte[] buf, int off, int len); + + // Classpath's compression library supports flushing, but we + // don't. So this is a no-op here. + void flush() + { + } +} diff --git a/libjava/java/util/zip/DeflaterOutputStream.h b/libjava/java/util/zip/DeflaterOutputStream.h new file mode 100644 index 000000000..307f364ad --- /dev/null +++ b/libjava/java/util/zip/DeflaterOutputStream.h @@ -0,0 +1,34 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_DeflaterOutputStream__ +#define __java_util_zip_DeflaterOutputStream__ + +#pragma interface + +#include <java/io/FilterOutputStream.h> +#include <gcj/array.h> + + +class java::util::zip::DeflaterOutputStream : public ::java::io::FilterOutputStream +{ + +public: // actually protected + virtual void deflate(); +public: + DeflaterOutputStream(::java::io::OutputStream *); + DeflaterOutputStream(::java::io::OutputStream *, ::java::util::zip::Deflater *); + DeflaterOutputStream(::java::io::OutputStream *, ::java::util::zip::Deflater *, jint); + virtual void flush(); + virtual void finish(); + virtual void close(); + virtual void write(jint); + virtual void write(JArray< jbyte > *, jint, jint); +public: // actually protected + JArray< jbyte > * __attribute__((aligned(__alignof__( ::java::io::FilterOutputStream)))) buf; + ::java::util::zip::Deflater * def; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_DeflaterOutputStream__ diff --git a/libjava/java/util/zip/GZIPInputStream.h b/libjava/java/util/zip/GZIPInputStream.h new file mode 100644 index 000000000..20777faba --- /dev/null +++ b/libjava/java/util/zip/GZIPInputStream.h @@ -0,0 +1,41 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_GZIPInputStream__ +#define __java_util_zip_GZIPInputStream__ + +#pragma interface + +#include <java/util/zip/InflaterInputStream.h> +#include <gcj/array.h> + + +class java::util::zip::GZIPInputStream : public ::java::util::zip::InflaterInputStream +{ + +public: + GZIPInputStream(::java::io::InputStream *); + GZIPInputStream(::java::io::InputStream *, jint); + virtual void close(); + virtual jint read(JArray< jbyte > *, jint, jint); +private: + void readHeader(); + void readFooter(); +public: + static const jint GZIP_MAGIC = 35615; +public: // actually package-private + static const jint FTEXT = 1; + static const jint FHCRC = 2; + static const jint FEXTRA = 4; + static const jint FNAME = 8; + static const jint FCOMMENT = 16; +public: // actually protected + ::java::util::zip::CRC32 * __attribute__((aligned(__alignof__( ::java::util::zip::InflaterInputStream)))) crc; + jboolean eos; +private: + jboolean readGZIPHeader; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_GZIPInputStream__ diff --git a/libjava/java/util/zip/GZIPOutputStream.h b/libjava/java/util/zip/GZIPOutputStream.h new file mode 100644 index 000000000..1680d8964 --- /dev/null +++ b/libjava/java/util/zip/GZIPOutputStream.h @@ -0,0 +1,28 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_GZIPOutputStream__ +#define __java_util_zip_GZIPOutputStream__ + +#pragma interface + +#include <java/util/zip/DeflaterOutputStream.h> +#include <gcj/array.h> + + +class java::util::zip::GZIPOutputStream : public ::java::util::zip::DeflaterOutputStream +{ + +public: + GZIPOutputStream(::java::io::OutputStream *); + GZIPOutputStream(::java::io::OutputStream *, jint); + virtual void write(JArray< jbyte > *, jint, jint); + virtual void close(); + virtual void finish(); +public: // actually protected + ::java::util::zip::CRC32 * __attribute__((aligned(__alignof__( ::java::util::zip::DeflaterOutputStream)))) crc; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_GZIPOutputStream__ diff --git a/libjava/java/util/zip/Inflater.h b/libjava/java/util/zip/Inflater.h new file mode 100644 index 000000000..25ebdc6d6 --- /dev/null +++ b/libjava/java/util/zip/Inflater.h @@ -0,0 +1,58 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_Inflater__ +#define __java_util_zip_Inflater__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace gnu + { + namespace gcj + { + class RawData; + } + } +} + +class java::util::zip::Inflater : public ::java::lang::Object +{ + +public: + Inflater(); + Inflater(jboolean); +public: // actually protected + virtual void finalize(); +public: + virtual void end(); + virtual jboolean finished(); + virtual jint getAdler(); + virtual jint getRemaining(); + virtual jint getTotalIn(); + virtual jint getTotalOut(); + virtual jint inflate(JArray< jbyte > *); + virtual jint inflate(JArray< jbyte > *, jint, jint); +private: + void init(jboolean); +public: + virtual jboolean needsDictionary(); + virtual jboolean needsInput(); + virtual void reset(); + virtual void setDictionary(JArray< jbyte > *); + virtual void setDictionary(JArray< jbyte > *, jint, jint); + virtual void setInput(JArray< jbyte > *); + virtual void setInput(JArray< jbyte > *, jint, jint); +private: + ::gnu::gcj::RawData * __attribute__((aligned(__alignof__( ::java::lang::Object)))) zstream; + jboolean is_finished; + jboolean dict_needed; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_Inflater__ diff --git a/libjava/java/util/zip/Inflater.java b/libjava/java/util/zip/Inflater.java new file mode 100644 index 000000000..c51cde802 --- /dev/null +++ b/libjava/java/util/zip/Inflater.java @@ -0,0 +1,269 @@ +/* Inflater.java - Decompress a data stream + Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package java.util.zip; + +import gnu.gcj.RawData; + +/* Written using on-line Java Platform 1.2 API Specification + * and JCL book. + * Believed complete and correct. + */ + +/** + * Inflater is used to decompress data that has been compressed according + * to the "deflate" standard described in rfc1950. + * + * The usage is as following. First you have to set some input with + * <code>setInput()</code>, then inflate() it. If inflate doesn't + * inflate any bytes there may be three reasons: + * <ul> + * <li>needsInput() returns true because the input buffer is empty. + * You have to provide more input with <code>setInput()</code>. + * NOTE: needsInput() also returns true when, the stream is finished. + * </li> + * <li>needsDictionary() returns true, you have to provide a preset + * dictionary with <code>setDictionary()</code>.</li> + * <li>finished() returns true, the inflater has finished.</li> + * </ul> + * Once the first output byte is produced, a dictionary will not be + * needed at a later stage. + * + * @author John Leuner, Jochen Hoenicke + * @author Tom Tromey + * @date May 17, 1999 + * @since JDK 1.1 + */ +public class Inflater +{ + // The zlib stream. + private RawData zstream; + + // True if finished. + private boolean is_finished; + + // True if dictionary needed. + private boolean dict_needed; + + /** + * Creates a new inflater. + */ + public Inflater () + { + this (false); + } + + /** + * Creates a new inflater. + * @param nowrap true if no header and checksum field appears in the + * stream. This is used for GZIPed input. For compatibility with + * Sun JDK you should provide one byte of input more than needed in + * this case. + */ + public Inflater (boolean noHeader) + { + init (noHeader); + } + + /** + * Finalizes this object. + */ + protected void finalize () + { + end (); + } + + /** + * Frees all objects allocated by the inflater. There's no reason + * to call this, since you can just rely on garbage collection (even + * for the Sun implementation). Exists only for compatibility + * with Sun's JDK, where the compressor allocates native memory. + * If you call any method (even reset) afterwards the behaviour is + * <i>undefined</i>. + * @deprecated Just clear all references to inflater instead. + */ + public native void end (); + + /** + * Returns true, if the inflater has finished. This means, that no + * input is needed and no output can be produced. + */ + public synchronized boolean finished () + { + return is_finished; + } + + /** + * Gets the adler checksum. This is either the checksum of all + * uncompressed bytes returned by inflate(), or if needsDictionary() + * returns true (and thus no output was yet produced) this is the + * adler checksum of the expected dictionary. + * @returns the adler checksum. + */ + public native int getAdler (); + + /** + * Gets the number of unprocessed input. Useful, if the end of the + * stream is reached and you want to further process the bytes after + * the deflate stream. + * @return the number of bytes of the input which were not processed. + */ + public native int getRemaining (); + + /** + * Gets the total number of processed compressed input bytes. + * @return the total number of bytes of processed input bytes. + */ + public native int getTotalIn (); + + /** + * Gets the total number of output bytes returned by inflate(). + * @return the total number of output bytes. + */ + public native int getTotalOut (); + + /** + * Inflates the compressed stream to the output buffer. If this + * returns 0, you should check, whether needsDictionary(), + * needsInput() or finished() returns true, to determine why no + * further output is produced. + * @param buffer the output buffer. + * @return the number of bytes written to the buffer, 0 if no further + * output can be produced. + * @exception DataFormatException if deflated stream is invalid. + * @exception IllegalArgumentException if buf has length 0. + */ + public int inflate (byte[] buf) throws DataFormatException + { + return inflate (buf, 0, buf.length); + } + + /** + * Inflates the compressed stream to the output buffer. If this + * returns 0, you should check, whether needsDictionary(), + * needsInput() or finished() returns true, to determine why no + * further output is produced. + * @param buffer the output buffer. + * @param off the offset into buffer where the output should start. + * @param len the maximum length of the output. + * @return the number of bytes written to the buffer, 0 if no further + * output can be produced. + * @exception DataFormatException if deflated stream is invalid. + * @exception IndexOutOfBoundsException if the off and/or len are wrong. + */ + public native int inflate (byte[] buf, int off, int len) + throws DataFormatException; + + private native void init (boolean noHeader); + + /** + * Returns true, if a preset dictionary is needed to inflate the input. + */ + public synchronized boolean needsDictionary () + { + return dict_needed; + } + + /** + * Returns true, if the input buffer is empty. + * You should then call setInput(). <br> + * + * <em>NOTE</em>: This method also returns true when the stream is finished. + */ + public synchronized boolean needsInput () + { + return getRemaining () == 0; + } + + /** + * Resets the inflater so that a new stream can be decompressed. All + * pending input and output will be discarded. + */ + public native void reset (); + + /** + * Sets the preset dictionary. This should only be called, if + * needsDictionary() returns true and it should set the same + * dictionary, that was used for deflating. The getAdler() + * function returns the checksum of the dictionary needed. + * @param buffer the dictionary. + * @exception IllegalStateException if no dictionary is needed. + * @exception IllegalArgumentException if the dictionary checksum is + * wrong. + */ + public void setDictionary (byte[] buf) + { + setDictionary (buf, 0, buf.length); + } + + /** + * Sets the preset dictionary. This should only be called, if + * needsDictionary() returns true and it should set the same + * dictionary, that was used for deflating. The getAdler() + * function returns the checksum of the dictionary needed. + * @param buffer the dictionary. + * @param off the offset into buffer where the dictionary starts. + * @param len the length of the dictionary. + * @exception IllegalStateException if no dictionary is needed. + * @exception IllegalArgumentException if the dictionary checksum is + * wrong. + * @exception IndexOutOfBoundsException if the off and/or len are wrong. + */ + public native void setDictionary (byte[] buf, int off, int len); + + /** + * Sets the input. This should only be called, if needsInput() + * returns true. + * @param buffer the input. + * @exception IllegalStateException if no input is needed. + */ + public void setInput (byte[] buf) + { + setInput (buf, 0, buf.length); + } + + /** + * Sets the input. This should only be called, if needsInput() + * returns true. + * @param buffer the input. + * @param off the offset into buffer where the input starts. + * @param len the length of the input. + * @exception IllegalStateException if no input is needed. + * @exception IndexOutOfBoundsException if the off and/or len are wrong. + */ + public native void setInput (byte[] buf, int off, int len); +} diff --git a/libjava/java/util/zip/InflaterInputStream.h b/libjava/java/util/zip/InflaterInputStream.h new file mode 100644 index 000000000..b576c3646 --- /dev/null +++ b/libjava/java/util/zip/InflaterInputStream.h @@ -0,0 +1,41 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_InflaterInputStream__ +#define __java_util_zip_InflaterInputStream__ + +#pragma interface + +#include <java/io/FilterInputStream.h> +#include <gcj/array.h> + + +class java::util::zip::InflaterInputStream : public ::java::io::FilterInputStream +{ + +public: + InflaterInputStream(::java::io::InputStream *); + InflaterInputStream(::java::io::InputStream *, ::java::util::zip::Inflater *); + InflaterInputStream(::java::io::InputStream *, ::java::util::zip::Inflater *, jint); + virtual jint available(); + virtual void close(); +public: // actually protected + virtual void fill(); +public: + virtual jint read(); + virtual jint read(JArray< jbyte > *, jint, jint); + virtual jlong skip(jlong); + virtual jboolean markSupported(); + virtual void mark(jint); + virtual void reset(); +public: // actually protected + ::java::util::zip::Inflater * __attribute__((aligned(__alignof__( ::java::io::FilterInputStream)))) inf; + JArray< jbyte > * buf; + jint len; +private: + JArray< jbyte > * onebytebuffer; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_InflaterInputStream__ diff --git a/libjava/java/util/zip/ZipConstants.h b/libjava/java/util/zip/ZipConstants.h new file mode 100644 index 000000000..3cf795d7b --- /dev/null +++ b/libjava/java/util/zip/ZipConstants.h @@ -0,0 +1,58 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipConstants__ +#define __java_util_zip_ZipConstants__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::util::zip::ZipConstants : public ::java::lang::Object +{ + +public: + static const jint LOCHDR = 30; + static const jlong LOCSIG = 67324752LL; + static const jint LOCVER = 4; + static const jint LOCFLG = 6; + static const jint LOCHOW = 8; + static const jint LOCTIM = 10; + static const jint LOCCRC = 14; + static const jint LOCSIZ = 18; + static const jint LOCLEN = 22; + static const jint LOCNAM = 26; + static const jint LOCEXT = 28; + static const jlong EXTSIG = 134695760LL; + static const jint EXTHDR = 16; + static const jint EXTCRC = 4; + static const jint EXTSIZ = 8; + static const jint EXTLEN = 12; + static const jlong CENSIG = 33639248LL; + static const jint CENHDR = 46; + static const jint CENVEM = 4; + static const jint CENVER = 6; + static const jint CENFLG = 8; + static const jint CENHOW = 10; + static const jint CENTIM = 12; + static const jint CENCRC = 16; + static const jint CENSIZ = 20; + static const jint CENLEN = 24; + static const jint CENNAM = 28; + static const jint CENEXT = 30; + static const jint CENCOM = 32; + static const jint CENDSK = 34; + static const jint CENATT = 36; + static const jint CENATX = 38; + static const jint CENOFF = 42; + static const jlong ENDSIG = 101010256LL; + static const jint ENDHDR = 22; + static const jint ENDSUB = 8; + static const jint ENDTOT = 10; + static const jint ENDSIZ = 12; + static const jint ENDOFF = 16; + static const jint ENDCOM = 20; + static ::java::lang::Class class$; +} __attribute__ ((java_interface)); + +#endif // __java_util_zip_ZipConstants__ diff --git a/libjava/java/util/zip/ZipEntry.h b/libjava/java/util/zip/ZipEntry.h new file mode 100644 index 000000000..47cb903a8 --- /dev/null +++ b/libjava/java/util/zip/ZipEntry.h @@ -0,0 +1,72 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipEntry__ +#define __java_util_zip_ZipEntry__ + +#pragma interface + +#include <java/lang/Object.h> +#include <gcj/array.h> + + +class java::util::zip::ZipEntry : public ::java::lang::Object +{ + +public: + ZipEntry(::java::lang::String *); + ZipEntry(::java::util::zip::ZipEntry *); +public: // actually package-private + ZipEntry(::java::util::zip::ZipEntry *, ::java::lang::String *); + virtual void setDOSTime(jint); + virtual jint getDOSTime(); +public: + virtual ::java::lang::Object * clone(); + virtual ::java::lang::String * getName(); + virtual void setTime(jlong); + virtual jlong getTime(); + virtual void setSize(jlong); + virtual jlong getSize(); + virtual void setCompressedSize(jlong); + virtual jlong getCompressedSize(); + virtual void setCrc(jlong); + virtual jlong getCrc(); + virtual void setMethod(jint); + virtual jint getMethod(); + virtual void setExtra(JArray< jbyte > *); +private: + void parseExtra(); +public: + virtual JArray< jbyte > * getExtra(); + virtual void setComment(::java::lang::String *); + virtual ::java::lang::String * getComment(); + virtual jboolean isDirectory(); + virtual ::java::lang::String * toString(); + virtual jint hashCode(); +private: + static const jbyte KNOWN_SIZE = 1; + static const jbyte KNOWN_CSIZE = 2; + static const jbyte KNOWN_CRC = 4; + static const jbyte KNOWN_TIME = 8; + static const jbyte KNOWN_DOSTIME = 16; + static const jbyte KNOWN_EXTRA = 32; + ::java::lang::String * __attribute__((aligned(__alignof__( ::java::lang::Object)))) name; + jint size; + jlong compressedSize; + jint crc; + ::java::lang::String * comment; + jbyte method; + jbyte known; + jint dostime; + jlong time; + JArray< jbyte > * extra; +public: // actually package-private + jint flags; + jint offset; +public: + static const jint STORED = 0; + static const jint DEFLATED = 8; + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipEntry__ diff --git a/libjava/java/util/zip/ZipException.h b/libjava/java/util/zip/ZipException.h new file mode 100644 index 000000000..3a7b1fc5e --- /dev/null +++ b/libjava/java/util/zip/ZipException.h @@ -0,0 +1,23 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipException__ +#define __java_util_zip_ZipException__ + +#pragma interface + +#include <java/io/IOException.h> + +class java::util::zip::ZipException : public ::java::io::IOException +{ + +public: + ZipException(); + ZipException(::java::lang::String *); +private: + static const jlong serialVersionUID = 8000196834066748623LL; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipException__ diff --git a/libjava/java/util/zip/ZipFile$1.h b/libjava/java/util/zip/ZipFile$1.h new file mode 100644 index 000000000..d181256c2 --- /dev/null +++ b/libjava/java/util/zip/ZipFile$1.h @@ -0,0 +1,26 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipFile$1__ +#define __java_util_zip_ZipFile$1__ + +#pragma interface + +#include <java/util/zip/InflaterInputStream.h> + +class java::util::zip::ZipFile$1 : public ::java::util::zip::InflaterInputStream +{ + +public: // actually package-private + ZipFile$1(::java::util::zip::ZipFile *, ::java::io::InputStream *, ::java::util::zip::Inflater *, jint); +public: + virtual jint available(); +public: // actually package-private + ::java::util::zip::ZipFile * __attribute__((aligned(__alignof__( ::java::util::zip::InflaterInputStream)))) this$0; +private: + jint val$sz; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipFile$1__ diff --git a/libjava/java/util/zip/ZipFile$PartialInputStream.h b/libjava/java/util/zip/ZipFile$PartialInputStream.h new file mode 100644 index 000000000..f258f9f0c --- /dev/null +++ b/libjava/java/util/zip/ZipFile$PartialInputStream.h @@ -0,0 +1,66 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipFile$PartialInputStream__ +#define __java_util_zip_ZipFile$PartialInputStream__ + +#pragma interface + +#include <java/io/InputStream.h> +#include <gcj/array.h> + +extern "Java" +{ + namespace java + { + namespace nio + { + namespace charset + { + class Charset; + class CharsetDecoder; + } + } + } +} + +class java::util::zip::ZipFile$PartialInputStream : public ::java::io::InputStream +{ + +public: + ZipFile$PartialInputStream(::java::io::RandomAccessFile *, jint); +public: // actually package-private + void setLength(jlong); +private: + void fillBuffer(); +public: + jint available(); + jint read(); + jint read(JArray< jbyte > *, jint, jint); + jlong skip(jlong); +public: // actually package-private + void seek(jlong); + void readFully(JArray< jbyte > *); + void readFully(JArray< jbyte > *, jint, jint); + jint readLeShort(); + jint readLeInt(); +private: + ::java::lang::String * decodeChars(JArray< jbyte > *, jint, jint); +public: // actually package-private + ::java::lang::String * readString(jint); +public: + void addDummyByte(); +private: + static ::java::nio::charset::Charset * UTF8CHARSET; + ::java::nio::charset::CharsetDecoder * __attribute__((aligned(__alignof__( ::java::io::InputStream)))) utf8Decoder; + ::java::io::RandomAccessFile * raf; + JArray< jbyte > * buffer; + jlong bufferOffset; + jint pos; + jlong end; + jint dummyByteCount; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipFile$PartialInputStream__ diff --git a/libjava/java/util/zip/ZipFile$ZipEntryEnumeration.h b/libjava/java/util/zip/ZipFile$ZipEntryEnumeration.h new file mode 100644 index 000000000..f041ae04a --- /dev/null +++ b/libjava/java/util/zip/ZipFile$ZipEntryEnumeration.h @@ -0,0 +1,25 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipFile$ZipEntryEnumeration__ +#define __java_util_zip_ZipFile$ZipEntryEnumeration__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::util::zip::ZipFile$ZipEntryEnumeration : public ::java::lang::Object +{ + +public: + ZipFile$ZipEntryEnumeration(::java::util::Iterator *); + virtual jboolean hasMoreElements(); + virtual ::java::util::zip::ZipEntry * ZipFile$ZipEntryEnumeration$nextElement(); + virtual ::java::lang::Object * nextElement(); +private: + ::java::util::Iterator * __attribute__((aligned(__alignof__( ::java::lang::Object)))) elements; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipFile$ZipEntryEnumeration__ diff --git a/libjava/java/util/zip/ZipFile.h b/libjava/java/util/zip/ZipFile.h new file mode 100644 index 000000000..7c0f69ca2 --- /dev/null +++ b/libjava/java/util/zip/ZipFile.h @@ -0,0 +1,49 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipFile__ +#define __java_util_zip_ZipFile__ + +#pragma interface + +#include <java/lang/Object.h> + +class java::util::zip::ZipFile : public ::java::lang::Object +{ + + ::java::io::RandomAccessFile * openFile(::java::lang::String *, ::java::io::File *); +public: + ZipFile(::java::lang::String *); + ZipFile(::java::io::File *); + ZipFile(::java::io::File *, jint); +private: + void checkZipFile(); + void checkClosed(); + void readEntries(); +public: + virtual void close(); +public: // actually protected + virtual void finalize(); +public: + virtual ::java::util::Enumeration * entries(); +private: + ::java::util::LinkedHashMap * getEntries(); +public: + virtual ::java::util::zip::ZipEntry * getEntry(::java::lang::String *); + virtual ::java::io::InputStream * getInputStream(::java::util::zip::ZipEntry *); + virtual ::java::lang::String * getName(); + virtual jint size(); + static const jint OPEN_READ = 1; + static const jint OPEN_DELETE = 4; +public: // actually package-private + static const jint ENDNRD = 4; +private: + ::java::lang::String * __attribute__((aligned(__alignof__( ::java::lang::Object)))) name; + ::java::io::RandomAccessFile * raf; + ::java::util::LinkedHashMap * entries__; + jboolean closed; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipFile__ diff --git a/libjava/java/util/zip/ZipInputStream.h b/libjava/java/util/zip/ZipInputStream.h new file mode 100644 index 000000000..4a8439506 --- /dev/null +++ b/libjava/java/util/zip/ZipInputStream.h @@ -0,0 +1,50 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipInputStream__ +#define __java_util_zip_ZipInputStream__ + +#pragma interface + +#include <java/util/zip/InflaterInputStream.h> +#include <gcj/array.h> + + +class java::util::zip::ZipInputStream : public ::java::util::zip::InflaterInputStream +{ + +public: + ZipInputStream(::java::io::InputStream *); +private: + void fillBuf(); + jint readBuf(JArray< jbyte > *, jint, jint); + void readFully(JArray< jbyte > *); + jint readLeByte(); + jint readLeShort(); + jint readLeInt(); +public: + virtual ::java::util::zip::ZipEntry * getNextEntry(); +private: + void readDataDescr(); +public: + virtual void closeEntry(); + virtual jint available(); + virtual jint read(); + virtual jint read(JArray< jbyte > *, jint, jint); + virtual void close(); +public: // actually protected + virtual ::java::util::zip::ZipEntry * createZipEntry(::java::lang::String *); +private: + ::java::util::zip::CRC32 * __attribute__((aligned(__alignof__( ::java::util::zip::InflaterInputStream)))) crc; + ::java::util::zip::ZipEntry * entry; + jint csize; + jint size; + jint method; + jint flags; + jint avail; + jboolean entryAtEOF; +public: + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipInputStream__ diff --git a/libjava/java/util/zip/ZipOutputStream.h b/libjava/java/util/zip/ZipOutputStream.h new file mode 100644 index 000000000..0de152efc --- /dev/null +++ b/libjava/java/util/zip/ZipOutputStream.h @@ -0,0 +1,47 @@ + +// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*- + +#ifndef __java_util_zip_ZipOutputStream__ +#define __java_util_zip_ZipOutputStream__ + +#pragma interface + +#include <java/util/zip/DeflaterOutputStream.h> +#include <gcj/array.h> + + +class java::util::zip::ZipOutputStream : public ::java::util::zip::DeflaterOutputStream +{ + +public: + ZipOutputStream(::java::io::OutputStream *); + virtual void setComment(::java::lang::String *); + virtual void setMethod(jint); + virtual void setLevel(jint); +private: + void writeLeShort(jint); + void writeLeInt(jint); + void writeLeInt(jlong); +public: + virtual void putNextEntry(::java::util::zip::ZipEntry *); + virtual void closeEntry(); + virtual void write(JArray< jbyte > *, jint, jint); + virtual void finish(); +private: + ::java::util::Vector * __attribute__((aligned(__alignof__( ::java::util::zip::DeflaterOutputStream)))) entries; + ::java::util::zip::CRC32 * crc; + ::java::util::zip::ZipEntry * curEntry; + jint curMethod; + jint size; + jint offset; + JArray< jbyte > * zipComment; + jint defaultMethod; + static const jint ZIP_STORED_VERSION = 10; + static const jint ZIP_DEFLATED_VERSION = 20; +public: + static const jint STORED = 0; + static const jint DEFLATED = 8; + static ::java::lang::Class class$; +}; + +#endif // __java_util_zip_ZipOutputStream__ diff --git a/libjava/java/util/zip/natDeflater.cc b/libjava/java/util/zip/natDeflater.cc new file mode 100644 index 000000000..9ff172109 --- /dev/null +++ b/libjava/java/util/zip/natDeflater.cc @@ -0,0 +1,216 @@ +// natDeflater.cc - Implementation of Deflater native methods. + +/* Copyright (C) 1999, 2002, 2006 Free Software Foundation + + 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 <stdlib.h> + +#include <gcj/cni.h> +#include <jvm.h> + +#include <java/util/zip/Deflater.h> +#include <java/util/zip/DataFormatException.h> + +#include <java/lang/InternalError.h> +#include <java/lang/NullPointerException.h> +#include <java/lang/ArrayIndexOutOfBoundsException.h> + +extern void *_Jv_ZMalloc (void *, uInt nitems, uInt size); +extern void _Jv_ZFree (void *, void *addr); + + + +jint +java::util::zip::Deflater::deflate (jbyteArray buf, jint off, jint len) +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + + if (! buf) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + throw new java::lang::ArrayIndexOutOfBoundsException; + + if (len == 0) + return 0; + + s->next_out = (Bytef *) (elements (buf) + off); + s->avail_out = len; + + switch (::deflate (s, flush_flag)) + { + case Z_STREAM_END: + is_finished = true; + if (s->avail_out == (unsigned int) len) + return -1; + break; + + case Z_STREAM_ERROR: + case Z_BUF_ERROR: + // FIXME? + throw new java::lang::InternalError; + break; + + case Z_OK: + break; + } + + return len - s->avail_out; +} + +void +java::util::zip::Deflater::end () +{ + JvSynchronize sync (this); + // Just ignore errors. + deflateEnd ((z_streamp) zstream); + _Jv_Free (zstream); + zstream = NULL; +} + +void +java::util::zip::Deflater::finish () +{ + JvSynchronize sync (this); + flush_flag = Z_FINISH; +} + +jint +java::util::zip::Deflater::getAdler () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + return s->adler; +} + +jlong +java::util::zip::Deflater::getBytesRead () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + return s->total_in; +} + +jlong +java::util::zip::Deflater::getBytesWritten () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + return s->total_out; +} + +jboolean +java::util::zip::Deflater::needsInput () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + return s->avail_in == 0; +} + +void +java::util::zip::Deflater::reset () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + // Just ignore errors. + deflateReset (s); + s->avail_in = 0; + flush_flag = 0; + is_finished = false; +} + +void +java::util::zip::Deflater::setDictionary (jbyteArray buf, jint off, jint len) +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + + if (! buf) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + throw new java::lang::ArrayIndexOutOfBoundsException; + + // Ignore errors. + deflateSetDictionary (s, (Bytef *) (elements (buf) + off), len); +} + +void +java::util::zip::Deflater::setInput (jbyteArray buf, jint off, jint len) +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + + if (! buf) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + throw new java::lang::ArrayIndexOutOfBoundsException; + + s->next_in = (Bytef *) (elements (buf) + off); + s->avail_in = len; +} + +void +java::util::zip::Deflater::update () +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + + int strat = Z_DEFAULT_STRATEGY; + switch (strategy) + { + case DEFAULT_STRATEGY: + strat = Z_DEFAULT_STRATEGY; + break; + case FILTERED: + strat = Z_FILTERED; + break; + case HUFFMAN_ONLY: + strat = Z_HUFFMAN_ONLY; + break; + default: + JvFail ("unexpected strategy"); + } + + // Ignore errors. + deflateParams (s, level, strat); +} + +void +java::util::zip::Deflater::init (jint level, 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; + +#define DEFAULT_MEM_LEVEL 8 + if (deflateInit2 (stream, level, Z_DEFLATED, wbits, + DEFAULT_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK) + { + jstring msg = NULL; + if (stream->msg != NULL) + msg = JvNewStringLatin1 (stream->msg); + throw new java::lang::InternalError (msg); + } + + zstream = reinterpret_cast<gnu::gcj::RawData *> (stream); + is_finished = false; + flush_flag = 0; +} diff --git a/libjava/java/util/zip/natInflater.cc b/libjava/java/util/zip/natInflater.cc new file mode 100644 index 000000000..69de6c335 --- /dev/null +++ b/libjava/java/util/zip/natInflater.cc @@ -0,0 +1,214 @@ +// natInflater.cc - Implementation of Inflater native methods. + +/* Copyright (C) 1999, 2002 Free Software Foundation + + 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 <stdlib.h> + +#include <gcj/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; +} + +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) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + throw new java::lang::ArrayIndexOutOfBoundsException; + + if (len == 0) + return 0; + + s->next_out = (Bytef *) (elements (buf) + off); + s->avail_out = len; + + switch (::inflate (s, Z_SYNC_FLUSH)) + { + case Z_BUF_ERROR: + /* Using the no_header option, zlib requires an extra padding byte at the + end of the stream in order to successfully complete decompression (see + zlib/contrib/minizip/unzip.c). We don't do this, so can end up with a + Z_BUF_ERROR at the end of a stream when zlib has completed inflation + and there's no more input. Thats not a problem. */ + if (s->avail_in != 0) + throw new java::lang::InternalError; + // Fall through. + + case Z_STREAM_END: + is_finished = true; + if (s->avail_out == (unsigned int) len) + return -1; + break; + + case Z_NEED_DICT: + dict_needed = true; + break; + + case Z_DATA_ERROR: + throw new java::util::zip::DataFormatException + (s->msg == NULL ? NULL : JvNewStringLatin1 (s->msg)); + break; + + case Z_MEM_ERROR: + throw new java::lang::OutOfMemoryError; + 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); + s->avail_in = 0; + is_finished = false; + dict_needed = false; +} + +void +java::util::zip::Inflater::setDictionary (jbyteArray buf, jint off, jint len) +{ + JvSynchronize sync (this); + z_streamp s = (z_streamp) zstream; + + if (! buf) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + 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) + throw new java::lang::NullPointerException; + if (off < 0 || len < 0 || off + len > buf->length) + throw new java::lang::ArrayIndexOutOfBoundsException; + + 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); + throw new java::lang::InternalError (msg); + } + + zstream = reinterpret_cast<gnu::gcj::RawData *> (stream); + is_finished = false; + dict_needed = false; +} |