|
From: <chr...@us...> - 2009-04-03 05:36:48
|
Revision: 5212
http://jnode.svn.sourceforge.net/jnode/?rev=5212&view=rev
Author: chrisboertien
Date: 2009-04-03 05:36:41 +0000 (Fri, 03 Apr 2009)
Log Message:
-----------
Revert java.util.zip back to classpath implementation
Signed-off-by: Chris Boertien <chr...@gm...>
Added Paths:
-----------
trunk/core/src/classpath/java/java/util/zip/Adler32.java
trunk/core/src/classpath/java/java/util/zip/CRC32.java
trunk/core/src/classpath/java/java/util/zip/CheckedInputStream.java
trunk/core/src/classpath/java/java/util/zip/CheckedOutputStream.java
trunk/core/src/classpath/java/java/util/zip/Checksum.java
trunk/core/src/classpath/java/java/util/zip/DataFormatException.java
trunk/core/src/classpath/java/java/util/zip/DeflaterOutputStream.java
trunk/core/src/classpath/java/java/util/zip/GZIPInputStream.java
trunk/core/src/classpath/java/java/util/zip/GZIPOutputStream.java
trunk/core/src/classpath/java/java/util/zip/InflaterInputStream.java
trunk/core/src/classpath/java/java/util/zip/ZipConstants.java
trunk/core/src/classpath/java/java/util/zip/ZipEntry.java
trunk/core/src/classpath/java/java/util/zip/ZipException.java
trunk/core/src/classpath/java/java/util/zip/ZipFile.java
trunk/core/src/classpath/java/java/util/zip/ZipInputStream.java
trunk/core/src/classpath/java/java/util/zip/ZipOutputStream.java
trunk/core/src/classpath/java/java/util/zip/package.html
Removed Paths:
-------------
trunk/core/src/openjdk/java/java/util/zip/Adler32.java
trunk/core/src/openjdk/java/java/util/zip/CRC32.java
trunk/core/src/openjdk/java/java/util/zip/CheckedInputStream.java
trunk/core/src/openjdk/java/java/util/zip/CheckedOutputStream.java
trunk/core/src/openjdk/java/java/util/zip/Checksum.java
trunk/core/src/openjdk/java/java/util/zip/DataFormatException.java
trunk/core/src/openjdk/java/java/util/zip/DeflaterOutputStream.java
trunk/core/src/openjdk/java/java/util/zip/GZIPInputStream.java
trunk/core/src/openjdk/java/java/util/zip/GZIPOutputStream.java
trunk/core/src/openjdk/java/java/util/zip/InflaterInputStream.java
trunk/core/src/openjdk/java/java/util/zip/ZipConstants.java
trunk/core/src/openjdk/java/java/util/zip/ZipEntry.java
trunk/core/src/openjdk/java/java/util/zip/ZipError.java
trunk/core/src/openjdk/java/java/util/zip/ZipException.java
trunk/core/src/openjdk/java/java/util/zip/ZipFile.java
trunk/core/src/openjdk/java/java/util/zip/ZipInputStream.java
trunk/core/src/openjdk/java/java/util/zip/ZipOutputStream.java
trunk/core/src/openjdk/java/java/util/zip/package.html
trunk/core/src/openjdk/vm/java/util/zip/NativeAdler32.java
trunk/core/src/openjdk/vm/java/util/zip/NativeCRC32.java
trunk/core/src/openjdk/vm/java/util/zip/NativeZipEntry.java
trunk/core/src/openjdk/vm/java/util/zip/NativeZipFile.java
trunk/core/src/openjdk/vm/java/util/zip/PartialInputStream.java
trunk/core/src/openjdk/vm/java/util/zip/StructCache.java
trunk/core/src/openjdk/vm/java/util/zip/ZipEntryStruct.java
trunk/core/src/openjdk/vm/java/util/zip/ZipFileStruct.java
trunk/core/src/openjdk/vm/java/util/zip/ZipUtil.java
Added: trunk/core/src/classpath/java/java/util/zip/Adler32.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/Adler32.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/Adler32.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,205 @@
+/* Adler32.java - Computes Adler32 data checksum of a data stream
+ Copyright (C) 1999, 2000, 2001 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;
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * The actual Adler32 algorithm is taken from RFC 1950.
+ * Status: Believed complete and correct.
+ */
+
+/**
+ * Computes Adler32 checksum for a stream of data. An Adler32
+ * checksum is not as reliable as a CRC32 checksum, but a lot faster to
+ * compute.
+ *<p>
+ * The specification for Adler32 may be found in RFC 1950.
+ * (ZLIB Compressed Data Format Specification version 3.3)
+ *<p>
+ *<p>
+ * From that document:
+ *<p>
+ * "ADLER32 (Adler-32 checksum)
+ * This contains a checksum value of the uncompressed data
+ * (excluding any dictionary data) computed according to Adler-32
+ * algorithm. This algorithm is a 32-bit extension and improvement
+ * of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073
+ * standard.
+ *<p>
+ * Adler-32 is composed of two sums accumulated per byte: s1 is
+ * the sum of all bytes, s2 is the sum of all s1 values. Both sums
+ * are done modulo 65521. s1 is initialized to 1, s2 to zero. The
+ * Adler-32 checksum is stored as s2*65536 + s1 in most-
+ * significant-byte first (network) order."
+ *<p>
+ * "8.2. The Adler-32 algorithm
+ *<p>
+ * The Adler-32 algorithm is much faster than the CRC32 algorithm yet
+ * still provides an extremely low probability of undetected errors.
+ *<p>
+ * The modulo on unsigned long accumulators can be delayed for 5552
+ * bytes, so the modulo operation time is negligible. If the bytes
+ * are a, b, c, the second sum is 3a + 2b + c + 3, and so is position
+ * and order sensitive, unlike the first sum, which is just a
+ * checksum. That 65521 is prime is important to avoid a possible
+ * large class of two-byte errors that leave the check unchanged.
+ * (The Fletcher checksum uses 255, which is not prime and which also
+ * makes the Fletcher check insensitive to single byte changes 0 <->
+ * 255.)
+ *<p>
+ * The sum s1 is initialized to 1 instead of zero to make the length
+ * of the sequence part of s2, so that the length does not have to be
+ * checked separately. (Any sequence of zeroes has a Fletcher
+ * checksum of zero.)"
+ *
+ * @author John Leuner, Per Bothner
+ * @since JDK 1.1
+ *
+ * @see InflaterInputStream
+ * @see DeflaterOutputStream
+ */
+public class Adler32 implements Checksum
+{
+
+ /** largest prime smaller than 65536 */
+ private static final int BASE = 65521;
+
+ private int checksum; //we do all in int.
+
+ //Note that java doesn't have unsigned integers,
+ //so we have to be careful with what arithmetic
+ //we do. We return the checksum as a long to
+ //avoid sign confusion.
+
+ /**
+ * Creates a new instance of the <code>Adler32</code> class.
+ * The checksum starts off with a value of 1.
+ */
+ public Adler32 ()
+ {
+ reset();
+ }
+
+ /**
+ * Resets the Adler32 checksum to the initial value.
+ */
+ public void reset ()
+ {
+ checksum = 1; //Initialize to 1
+ }
+
+ /**
+ * Updates the checksum with the byte b.
+ *
+ * @param bval the data value to add. The high byte of the int is ignored.
+ */
+ public void update (int bval)
+ {
+ //We could make a length 1 byte array and call update again, but I
+ //would rather not have that overhead
+ int s1 = checksum & 0xffff;
+ int s2 = checksum >>> 16;
+
+ s1 = (s1 + (bval & 0xFF)) % BASE;
+ s2 = (s1 + s2) % BASE;
+
+ checksum = (s2 << 16) + s1;
+ }
+
+ /**
+ * Updates the checksum with the bytes taken from the array.
+ *
+ * @param buffer an array of bytes
+ */
+ public void update (byte[] buffer)
+ {
+ update(buffer, 0, buffer.length);
+ }
+
+ /**
+ * Updates the checksum with the bytes taken from the array.
+ *
+ * @param buf an array of bytes
+ * @param off the start of the data used for this update
+ * @param len the number of bytes to use for this update
+ */
+ public void update (byte[] buf, int off, int len)
+ {
+ //(By Per Bothner)
+ int s1 = checksum & 0xffff;
+ int s2 = checksum >>> 16;
+
+ while (len > 0)
+ {
+ // We can defer the modulo operation:
+ // s1 maximally grows from 65521 to 65521 + 255 * 3800
+ // s2 maximally grows by 3800 * median(s1) = 2090079800 < 2^31
+ int n = 3800;
+ if (n > len)
+ n = len;
+ len -= n;
+ while (--n >= 0)
+ {
+ s1 = s1 + (buf[off++] & 0xFF);
+ s2 = s2 + s1;
+ }
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+
+ /*Old implementation, borrowed from somewhere:
+ int n;
+
+ while (len-- > 0) {
+
+ s1 = (s1 + (bs[offset++] & 0xff)) % BASE;
+ s2 = (s2 + s1) % BASE;
+ }*/
+
+ checksum = (s2 << 16) | s1;
+ }
+
+ /**
+ * Returns the Adler32 data checksum computed so far.
+ */
+ public long getValue()
+ {
+ return (long) checksum & 0xffffffffL;
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/CRC32.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/CRC32.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/CRC32.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,132 @@
+/* CRC32.java - Computes CRC32 data checksum of a data stream
+ Copyright (C) 1999. 2000, 2001 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;
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * The actual CRC32 algorithm is taken from RFC 1952.
+ * Status: Believed complete and correct.
+ */
+
+/**
+ * Computes CRC32 data checksum of a data stream.
+ * The actual CRC32 algorithm is described in RFC 1952
+ * (GZIP file format specification version 4.3).
+ * Can be used to get the CRC32 over a stream if used with checked input/output
+ * streams.
+ *
+ * @see InflaterInputStream
+ * @see DeflaterOutputStream
+ *
+ * @author Per Bothner
+ * @date April 1, 1999.
+ */
+public class CRC32 implements Checksum
+{
+ /** The crc data checksum so far. */
+ private int crc = 0;
+
+ /** The fast CRC table. Computed once when the CRC32 class is loaded. */
+ private static int[] crc_table = make_crc_table();
+
+ /** Make the table for a fast CRC. */
+ private static int[] make_crc_table ()
+ {
+ int[] crc_table = new int[256];
+ for (int n = 0; n < 256; n++)
+ {
+ int c = n;
+ for (int k = 8; --k >= 0; )
+ {
+ if ((c & 1) != 0)
+ c = 0xedb88320 ^ (c >>> 1);
+ else
+ c = c >>> 1;
+ }
+ crc_table[n] = c;
+ }
+ return crc_table;
+ }
+
+ /**
+ * Returns the CRC32 data checksum computed so far.
+ */
+ public long getValue ()
+ {
+ return (long) crc & 0xffffffffL;
+ }
+
+ /**
+ * Resets the CRC32 data checksum as if no update was ever called.
+ */
+ public void reset () { crc = 0; }
+
+ /**
+ * Updates the checksum with the int bval.
+ *
+ * @param bval (the byte is taken as the lower 8 bits of bval)
+ */
+
+ public void update (int bval)
+ {
+ int c = ~crc;
+ c = crc_table[(c ^ bval) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+
+ /**
+ * Adds the byte array to the data checksum.
+ *
+ * @param buf the buffer which contains the data
+ * @param off the offset in the buffer where the data starts
+ * @param len the length of the data
+ */
+ public void update (byte[] buf, int off, int len)
+ {
+ int c = ~crc;
+ while (--len >= 0)
+ c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
+ crc = ~c;
+ }
+
+ /**
+ * Adds the complete byte array to the data checksum.
+ */
+ public void update (byte[] buf) { update(buf, 0, buf.length); }
+}
Added: trunk/core/src/classpath/java/java/util/zip/CheckedInputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/CheckedInputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/CheckedInputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,135 @@
+/* CheckedInputStream.java - Compute checksum of data being read
+ Copyright (C) 1999, 2000, 2004 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 java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/* Written using on-line Java Platform 1.2 API Specification
+ * and JCL book.
+ * Believed complete and correct.
+ */
+
+/**
+ * InputStream that computes a checksum of the data being read using a
+ * supplied Checksum object.
+ *
+ * @see Checksum
+ *
+ * @author Tom Tromey
+ * @date May 17, 1999
+ */
+public class CheckedInputStream extends FilterInputStream
+{
+ /**
+ * Creates a new CheckInputStream on top of the supplied OutputStream
+ * using the supplied Checksum.
+ */
+ public CheckedInputStream (InputStream in, Checksum sum)
+ {
+ super (in);
+ this.sum = sum;
+ }
+
+ /**
+ * Returns the Checksum object used. To get the data checksum computed so
+ * far call <code>getChecksum.getValue()</code>.
+ */
+ public Checksum getChecksum ()
+ {
+ return sum;
+ }
+
+ /**
+ * Reads one byte, updates the checksum and returns the read byte
+ * (or -1 when the end of file was reached).
+ */
+ public int read () throws IOException
+ {
+ int x = in.read();
+ if (x != -1)
+ sum.update(x);
+ return x;
+ }
+
+ /**
+ * Reads at most len bytes in the supplied buffer and updates the checksum
+ * with it. Returns the number of bytes actually read or -1 when the end
+ * of file was reached.
+ */
+ public int read (byte[] buf, int off, int len) throws IOException
+ {
+ int r = in.read(buf, off, len);
+ if (r != -1)
+ sum.update(buf, off, r);
+ return r;
+ }
+
+ /**
+ * Skips n bytes by reading them in a temporary buffer and updating the
+ * the checksum with that buffer. Returns the actual number of bytes skiped
+ * which can be less then requested when the end of file is reached.
+ */
+ public long skip (long n) throws IOException
+ {
+ if (n == 0)
+ return 0;
+
+ int min = (int) Math.min(n, 1024);
+ byte[] buf = new byte[min];
+
+ long s = 0;
+ while (n > 0)
+ {
+ int r = in.read(buf, 0, min);
+ if (r == -1)
+ break;
+ n -= r;
+ s += r;
+ min = (int) Math.min(n, 1024);
+ sum.update(buf, 0, r);
+ }
+
+ return s;
+ }
+
+ /** The checksum object. */
+ private Checksum sum;
+}
Added: trunk/core/src/classpath/java/java/util/zip/CheckedOutputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/CheckedOutputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/CheckedOutputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,100 @@
+/* CheckedOutputStream.java - Compute checksum of data being written.
+ Copyright (C) 1999, 2000 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 java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/* Written using on-line Java Platform 1.2 API Specification
+ * and JCL book.
+ * Believed complete and correct.
+ */
+
+/**
+ * OutputStream that computes a checksum of data being written using a
+ * supplied Checksum object.
+ *
+ * @see Checksum
+ *
+ * @author Tom Tromey
+ * @date May 17, 1999
+ */
+public class CheckedOutputStream extends FilterOutputStream
+{
+ /**
+ * Creates a new CheckInputStream on top of the supplied OutputStream
+ * using the supplied Checksum.
+ */
+ public CheckedOutputStream (OutputStream out, Checksum cksum)
+ {
+ super (out);
+ this.sum = cksum;
+ }
+
+ /**
+ * Returns the Checksum object used. To get the data checksum computed so
+ * far call <code>getChecksum.getValue()</code>.
+ */
+ public Checksum getChecksum ()
+ {
+ return sum;
+ }
+
+ /**
+ * Writes one byte to the OutputStream and updates the Checksum.
+ */
+ public void write (int bval) throws IOException
+ {
+ out.write(bval);
+ sum.update(bval);
+ }
+
+ /**
+ * Writes the byte array to the OutputStream and updates the Checksum.
+ */
+ public void write (byte[] buf, int off, int len) throws IOException
+ {
+ out.write(buf, off, len);
+ sum.update(buf, off, len);
+ }
+
+ /** The checksum object. */
+ private Checksum sum;
+}
Added: trunk/core/src/classpath/java/java/util/zip/Checksum.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/Checksum.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/Checksum.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,86 @@
+/* Checksum.java - Interface to compute a data checksum
+ Copyright (C) 1999, 2000, 2001 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;
+
+/*
+ * Written using on-line Java Platform 1.2 API Specification, as well
+ * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
+ * Status: Believed complete and correct.
+ */
+
+/**
+ * Interface to compute a data checksum used by checked input/output streams.
+ * A data checksum can be updated by one byte or with a byte array. After each
+ * update the value of the current checksum can be returned by calling
+ * <code>getValue</code>. The complete checksum object can also be reset
+ * so it can be used again with new data.
+ *
+ * @see CheckedInputStream
+ * @see CheckedOutputStream
+ *
+ * @author Per Bothner
+ * @author Jochen Hoenicke
+ */
+public interface Checksum
+{
+ /**
+ * Returns the data checksum computed so far.
+ */
+ long getValue();
+
+ /**
+ * Resets the data checksum as if no update was ever called.
+ */
+ void reset();
+
+ /**
+ * Adds one byte to the data checksum.
+ *
+ * @param bval the data value to add. The high byte of the int is ignored.
+ */
+ void update (int bval);
+
+ /**
+ * Adds the byte array to the data checksum.
+ *
+ * @param buf the buffer which contains the data
+ * @param off the offset in the buffer where the data starts
+ * @param len the length of the data
+ */
+ void update (byte[] buf, int off, int len);
+}
Added: trunk/core/src/classpath/java/java/util/zip/DataFormatException.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/DataFormatException.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/DataFormatException.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,71 @@
+/* DataformatException.java -- thrown when compressed data is corrupt
+ Copyright (C) 1999, 2000, 2001, 2002 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;
+
+/**
+ * Exception thrown when compressed data is corrupt.
+ *
+ * @author Tom Tromey
+ * @author John Leuner
+ * @since 1.1
+ * @status updated to 1.4
+ */
+public class DataFormatException extends Exception
+{
+ /**
+ * Compatible with JDK 1.1+.
+ */
+ private static final long serialVersionUID = 2219632870893641452L;
+
+ /**
+ * Create an exception without a message.
+ */
+ public DataFormatException()
+ {
+ }
+
+ /**
+ * Create an exception with a message.
+ *
+ * @param msg the message
+ */
+ public DataFormatException(String msg)
+ {
+ super(msg);
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/DeflaterOutputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/DeflaterOutputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/DeflaterOutputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,198 @@
+/* DeflaterOutputStream.java - Output filter for compressing.
+ Copyright (C) 1999, 2000, 2001, 2004, 2005 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 java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/* Written using on-line Java Platform 1.2 API Specification
+ * and JCL book.
+ * Believed complete and correct.
+ */
+
+/**
+ * This is a special FilterOutputStream deflating the bytes that are
+ * written through it. It uses the Deflater for deflating.
+ *
+ * A special thing to be noted is that flush() doesn't flush
+ * everything in Sun's JDK, but it does so in jazzlib. This is because
+ * Sun's Deflater doesn't have a way to flush() everything, without
+ * finishing the stream.
+ *
+ * @author Tom Tromey, Jochen Hoenicke
+ * @date Jan 11, 2001
+ */
+public class DeflaterOutputStream extends FilterOutputStream
+{
+ /**
+ * This buffer is used temporarily to retrieve the bytes from the
+ * deflater and write them to the underlying output stream.
+ */
+ protected byte[] buf;
+
+ /**
+ * The deflater which is used to deflate the stream.
+ */
+ protected Deflater def;
+
+ /**
+ * Deflates everything in the def's input buffers. This will call
+ * <code>def.deflate()</code> until all bytes from the input buffers
+ * are processed.
+ */
+ protected void deflate() throws IOException
+ {
+ while (! def.needsInput())
+ {
+ int len = def.deflate(buf, 0, buf.length);
+
+ // System.err.println("DOS deflated " + len + " out of " + buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len);
+ }
+
+ if (! def.needsInput())
+ throw new InternalError("Can't deflate all input?");
+ }
+
+ /**
+ * Creates a new DeflaterOutputStream with a default Deflater and
+ * default buffer size.
+ * @param out the output stream where deflated output should be written.
+ */
+ public DeflaterOutputStream(OutputStream out)
+ {
+ this(out, new Deflater(), 4096);
+ }
+
+ /**
+ * Creates a new DeflaterOutputStream with the given Deflater and
+ * default buffer size.
+ * @param out the output stream where deflated output should be written.
+ * @param defl the underlying deflater.
+ */
+ public DeflaterOutputStream(OutputStream out, Deflater defl)
+ {
+ this(out, defl, 4096);
+ }
+
+ /**
+ * Creates a new DeflaterOutputStream with the given Deflater and
+ * buffer size.
+ * @param out the output stream where deflated output should be written.
+ * @param defl the underlying deflater.
+ * @param bufsize the buffer size.
+ * @exception IllegalArgumentException if bufsize isn't positive.
+ */
+ public DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize)
+ {
+ super(out);
+ if (bufsize <= 0)
+ throw new IllegalArgumentException("bufsize <= 0");
+ buf = new byte[bufsize];
+ def = defl;
+ }
+
+ /**
+ * Flushes the stream by calling flush() on the deflater and then
+ * on the underlying stream. This ensures that all bytes are
+ * flushed. This function doesn't work in Sun's JDK, but only in
+ * jazzlib.
+ */
+ public void flush() throws IOException
+ {
+ def.flush();
+ deflate();
+ out.flush();
+ }
+
+ /**
+ * Finishes the stream by calling finish() on the deflater. This
+ * was the only way to ensure that all bytes are flushed in Sun's
+ * JDK.
+ */
+ public void finish() throws IOException
+ {
+ def.finish();
+ while (! def.finished())
+ {
+ int len = def.deflate(buf, 0, buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len);
+ }
+ if (! def.finished())
+ throw new InternalError("Can't deflate all input?");
+ out.flush();
+ }
+
+ /**
+ * Calls finish() and closes the stream.
+ */
+ public void close() throws IOException
+ {
+ finish();
+ out.close();
+ }
+
+ /**
+ * Writes a single byte to the compressed output stream.
+ * @param bval the byte value.
+ */
+ public void write(int bval) throws IOException
+ {
+ byte[] b = new byte[1];
+ b[0] = (byte) bval;
+ write(b, 0, 1);
+ }
+
+ /**
+ * Writes a len bytes from an array to the compressed stream.
+ * @param buf the byte array.
+ * @param off the offset into the byte array where to start.
+ * @param len the number of bytes to write.
+ */
+ public void write(byte[] buf, int off, int len) throws IOException
+ {
+ def.setInput(buf, off, len);
+ deflate();
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/GZIPInputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/GZIPInputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/GZIPInputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,355 @@
+/* GZIPInputStream.java - Input filter for reading gzip file
+ Copyright (C) 1999, 2000, 2001, 2002, 2004 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 java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * This filter stream is used to decompress a "GZIP" format stream.
+ * The "GZIP" format is described in RFC 1952.
+ *
+ * @author John Leuner
+ * @author Tom Tromey
+ * @since JDK 1.1
+ */
+public class GZIPInputStream
+ extends InflaterInputStream
+{
+ /**
+ * The magic number found at the start of a GZIP stream.
+ */
+ public static final int GZIP_MAGIC = 0x8b1f;
+
+ /**
+ * The mask for bit 0 of the flag byte.
+ */
+ static final int FTEXT = 0x1;
+
+ /**
+ * The mask for bit 1 of the flag byte.
+ */
+ static final int FHCRC = 0x2;
+
+ /**
+ * The mask for bit 2 of the flag byte.
+ */
+ static final int FEXTRA = 0x4;
+
+ /**
+ * The mask for bit 3 of the flag byte.
+ */
+ static final int FNAME = 0x8;
+
+ /**
+ * The mask for bit 4 of the flag byte.
+ */
+ static final int FCOMMENT = 0x10;
+
+ /**
+ * The CRC-32 checksum value for uncompressed data.
+ */
+ protected CRC32 crc;
+
+ /**
+ * Indicates whether or not the end of the stream has been reached.
+ */
+ protected boolean eos;
+
+ /**
+ * Indicates whether or not the GZIP header has been read in.
+ */
+ private boolean readGZIPHeader;
+
+ /**
+ * Creates a GZIPInputStream with the default buffer size.
+ *
+ * @param in The stream to read compressed data from
+ * (in GZIP format).
+ *
+ * @throws IOException if an error occurs during an I/O operation.
+ */
+ public GZIPInputStream(InputStream in)
+ throws IOException
+ {
+ this(in, 4096);
+ }
+
+ /**
+ * Creates a GZIPInputStream with the specified buffer size.
+ *
+ * @param in The stream to read compressed data from
+ * (in GZIP format).
+ * @param size The size of the buffer to use.
+ *
+ * @throws IOException if an error occurs during an I/O operation.
+ * @throws IllegalArgumentException if <code>size</code>
+ * is less than or equal to 0.
+ */
+ public GZIPInputStream(InputStream in, int size)
+ throws IOException
+ {
+ super(in, new Inflater(true), size);
+ crc = new CRC32();
+ readHeader();
+ }
+
+ /**
+ * Closes the input stream.
+ *
+ * @throws IOException if an error occurs during an I/O operation.
+ */
+ public void close()
+ throws IOException
+ {
+ // Nothing to do here.
+ super.close();
+ }
+
+ /**
+ * Reads in GZIP-compressed data and stores it in uncompressed form
+ * into an array of bytes. The method will block until either
+ * enough input data becomes available or the compressed stream
+ * reaches its end.
+ *
+ * @param buf the buffer into which the uncompressed data will
+ * be stored.
+ * @param offset the offset indicating where in <code>buf</code>
+ * the uncompressed data should be placed.
+ * @param len the number of uncompressed bytes to be read.
+ */
+ public int read(byte[] buf, int offset, int len) throws IOException
+ {
+ // We first have to slurp in the GZIP header, then we feed all the
+ // rest of the data to the superclass.
+ //
+ // As we do that we continually update the CRC32. Once the data is
+ // finished, we check the CRC32.
+ //
+ // This means we don't need our own buffer, as everything is done
+ // in the superclass.
+ if (!readGZIPHeader)
+ readHeader();
+
+ if (eos)
+ return -1;
+
+ // System.err.println("GZIPIS.read(byte[], off, len ... " + offset + " and len " + len);
+
+ /* We don't have to read the header,
+ * so we just grab data from the superclass.
+ */
+ int numRead = super.read(buf, offset, len);
+ if (numRead > 0)
+ crc.update(buf, offset, numRead);
+
+ if (inf.finished())
+ readFooter();
+ return numRead;
+ }
+
+
+ /**
+ * Reads in the GZIP header.
+ */
+ private void readHeader() throws IOException
+ {
+ /* 1. Check the two magic bytes */
+ CRC32 headCRC = new CRC32();
+ int magic = in.read();
+ if (magic < 0)
+ {
+ eos = true;
+ return;
+ }
+ int magic2 = in.read();
+ if ((magic + (magic2 << 8)) != GZIP_MAGIC)
+ throw new IOException("Error in GZIP header, bad magic code");
+ headCRC.update(magic);
+ headCRC.update(magic2);
+
+ /* 2. Check the compression type (must be 8) */
+ int CM = in.read();
+ if (CM != Deflater.DEFLATED)
+ throw new IOException("Error in GZIP header, data not in deflate format");
+ headCRC.update(CM);
+
+ /* 3. Check the flags */
+ int flags = in.read();
+ if (flags < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(flags);
+
+ /* This flag byte is divided into individual bits as follows:
+
+ bit 0 FTEXT
+ bit 1 FHCRC
+ bit 2 FEXTRA
+ bit 3 FNAME
+ bit 4 FCOMMENT
+ bit 5 reserved
+ bit 6 reserved
+ bit 7 reserved
+ */
+
+ /* 3.1 Check the reserved bits are zero */
+ if ((flags & 0xd0) != 0)
+ throw new IOException("Reserved flag bits in GZIP header != 0");
+
+ /* 4.-6. Skip the modification time, extra flags, and OS type */
+ for (int i=0; i< 6; i++)
+ {
+ int readByte = in.read();
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(readByte);
+ }
+
+ /* 7. Read extra field */
+ if ((flags & FEXTRA) != 0)
+ {
+ /* Skip subfield id */
+ for (int i=0; i< 2; i++)
+ {
+ int readByte = in.read();
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(readByte);
+ }
+ if (in.read() < 0 || in.read() < 0)
+ throw new EOFException("Early EOF in GZIP header");
+
+ int len1, len2, extraLen;
+ len1 = in.read();
+ len2 = in.read();
+ if ((len1 < 0) || (len2 < 0))
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(len1);
+ headCRC.update(len2);
+
+ extraLen = (len1 << 8) | len2;
+ for (int i = 0; i < extraLen;i++)
+ {
+ int readByte = in.read();
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+ headCRC.update(readByte);
+ }
+ }
+
+ /* 8. Read file name */
+ if ((flags & FNAME) != 0)
+ {
+ int readByte;
+ while ( (readByte = in.read()) > 0)
+ headCRC.update(readByte);
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP file name");
+ headCRC.update(readByte);
+ }
+
+ /* 9. Read comment */
+ if ((flags & FCOMMENT) != 0)
+ {
+ int readByte;
+ while ( (readByte = in.read()) > 0)
+ headCRC.update(readByte);
+
+ if (readByte < 0)
+ throw new EOFException("Early EOF in GZIP comment");
+ headCRC.update(readByte);
+ }
+
+ /* 10. Read header CRC */
+ if ((flags & FHCRC) != 0)
+ {
+ int tempByte;
+ int crcval = in.read();
+ if (crcval < 0)
+ throw new EOFException("Early EOF in GZIP header");
+
+ tempByte = in.read();
+ if (tempByte < 0)
+ throw new EOFException("Early EOF in GZIP header");
+
+ crcval = (crcval << 8) | tempByte;
+ if (crcval != ((int) headCRC.getValue() & 0xffff))
+ throw new IOException("Header CRC value mismatch");
+ }
+
+ readGZIPHeader = true;
+ //System.err.println("Read GZIP header");
+ }
+
+ private void readFooter() throws IOException
+ {
+ byte[] footer = new byte[8];
+ int avail = inf.getRemaining();
+ if (avail > 8)
+ avail = 8;
+ System.arraycopy(buf, len - inf.getRemaining(), footer, 0, avail);
+ int needed = 8 - avail;
+ while (needed > 0)
+ {
+ int count = in.read(footer, 8-needed, needed);
+ if (count <= 0)
+ throw new EOFException("Early EOF in GZIP footer");
+ needed -= count; //Jewel Jan 16
+ }
+
+ int crcval = (footer[0] & 0xff) | ((footer[1] & 0xff) << 8)
+ | ((footer[2] & 0xff) << 16) | (footer[3] << 24);
+ if (crcval != (int) crc.getValue())
+ throw new IOException("GZIP crc sum mismatch, theirs \""
+ + Integer.toHexString(crcval)
+ + "\" and ours \""
+ + Integer.toHexString( (int) crc.getValue()));
+
+ int total = (footer[4] & 0xff) | ((footer[5] & 0xff) << 8)
+ | ((footer[6] & 0xff) << 16) | (footer[7] << 24);
+ if (total != inf.getTotalOut())
+ throw new IOException("Number of bytes mismatch");
+
+ /* FIXME" XXX Should we support multiple members.
+ * Difficult, since there may be some bytes still in buf
+ */
+ eos = true;
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/GZIPOutputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/GZIPOutputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/GZIPOutputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,151 @@
+/* GZIPOutputStream.java - Create a file in gzip format
+ Copyright (C) 1999, 2000, 2001 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 java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * This filter stream is used to compress a stream into a "GZIP" stream.
+ * The "GZIP" format is described in RFC 1952.
+ *
+ * @author John Leuner
+ * @author Tom Tromey
+ * @since JDK 1.1
+ */
+
+/* Written using on-line Java Platform 1.2 API Specification
+ * and JCL book.
+ * Believed complete and correct.
+ */
+
+public class GZIPOutputStream extends DeflaterOutputStream
+{
+ /**
+ * CRC-32 value for uncompressed data
+ */
+ protected CRC32 crc;
+
+ /**
+ * Creates a GZIPOutputStream with the default buffer size
+ *
+ * @param out The stream to read data (to be compressed) from
+ *
+ */
+ public GZIPOutputStream(OutputStream out) throws IOException
+ {
+ this(out, 4096);
+ }
+
+ /**
+ * Creates a GZIPOutputStream with the specified buffer size
+ *
+ * @param out The stream to read compressed data from
+ * @param size Size of the buffer to use
+ */
+ public GZIPOutputStream(OutputStream out, int size) throws IOException
+ {
+ super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
+ crc = new CRC32();
+ int mod_time = (int) (System.currentTimeMillis() / 1000L);
+ byte[] gzipHeader =
+ {
+ /* The two magic bytes */
+ (byte) GZIPInputStream.GZIP_MAGIC,
+ (byte) (GZIPInputStream.GZIP_MAGIC >> 8),
+
+ /* The compression type */
+ (byte) Deflater.DEFLATED,
+
+ /* The flags (not set) */
+ 0,
+
+ /* The modification time */
+ (byte) mod_time, (byte) (mod_time >> 8),
+ (byte) (mod_time >> 16), (byte) (mod_time >> 24),
+
+ /* The extra flags */
+ 0,
+
+ /* The OS type (unknown) */
+ (byte) 255
+ };
+
+ out.write(gzipHeader);
+ // System.err.println("wrote GZIP header (" + gzipHeader.length + " bytes )");
+ }
+
+ public synchronized void write(byte[] buf, int off, int len)
+ throws IOException
+ {
+ super.write(buf, off, len);
+ crc.update(buf, off, len);
+ }
+
+ /**
+ * Writes remaining compressed output data to the output stream
+ * and closes it.
+ */
+ public void close() throws IOException
+ {
+ finish();
+ out.close();
+ }
+
+ public void finish() throws IOException
+ {
+ super.finish();
+
+ int totalin = def.getTotalIn();
+ int crcval = (int) (crc.getValue() & 0xffffffff);
+
+ // System.err.println("CRC val is " + Integer.toHexString( crcval ) + " and length " + Integer.toHexString(totalin));
+
+ byte[] gzipFooter =
+ {
+ (byte) crcval, (byte) (crcval >> 8),
+ (byte) (crcval >> 16), (byte) (crcval >> 24),
+
+ (byte) totalin, (byte) (totalin >> 8),
+ (byte) (totalin >> 16), (byte) (totalin >> 24)
+ };
+
+ out.write(gzipFooter);
+ // System.err.println("wrote GZIP trailer (" + gzipFooter.length + " bytes )");
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/InflaterInputStream.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/InflaterInputStream.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/InflaterInputStream.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,261 @@
+/* InflaterInputStream.java - Input stream filter for decompressing
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
+ 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 java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * This filter stream is used to decompress data compressed in the "deflate"
+ * format. The "deflate" format is described in RFC 1951.
+ *
+ * This stream may form the basis for other decompression filters, such
+ * as the <code>GZIPInputStream</code>.
+ *
+ * @author John Leuner
+ * @author Tom Tromey
+ * @since 1.1
+ */
+public class InflaterInputStream extends FilterInputStream
+{
+ /**
+ * Decompressor for this filter
+ */
+ protected Inflater inf;
+
+ /**
+ * Byte array used as a buffer
+ */
+ protected byte[] buf;
+
+ /**
+ * Size of buffer
+ */
+ protected int len;
+
+ // We just use this if we are decoding one byte at a time with the
+ // read() call.
+ private byte[] onebytebuffer = new byte[1];
+
+ /**
+ * Create an InflaterInputStream with the default decompresseor
+ * and a default buffer size.
+ *
+ * @param in the InputStream to read bytes from
+ */
+ public InflaterInputStream(InputStream in)
+ {
+ this(in, new Inflater(), 4096);
+ }
+
+ /**
+ * Create an InflaterInputStream with the specified decompresseor
+ * and a default buffer size.
+ *
+ * @param in the InputStream to read bytes from
+ * @param inf the decompressor used to decompress data read from in
+ */
+ public InflaterInputStream(InputStream in, Inflater inf)
+ {
+ this(in, inf, 4096);
+ }
+
+ /**
+ * Create an InflaterInputStream with the specified decompresseor
+ * and a specified buffer size.
+ *
+ * @param in the InputStream to read bytes from
+ * @param inf the decompressor used to decompress data read from in
+ * @param size size of the buffer to use
+ */
+ public InflaterInputStream(InputStream in, Inflater inf, int size)
+ {
+ super(in);
+
+ if (in == null)
+ throw new NullPointerException("in may not be null");
+ if (inf == null)
+ throw new NullPointerException("inf may not be null");
+ if (size < 0)
+ throw new IllegalArgumentException("size may not be negative");
+
+ this.inf = inf;
+ this.buf = new byte [size];
+ }
+
+ /**
+ * Returns 0 once the end of the stream (EOF) has been reached.
+ * Otherwise returns 1.
+ */
+ public int available() throws IOException
+ {
+ // According to the JDK 1.2 docs, this should only ever return 0
+ // or 1 and should not be relied upon by Java programs.
+ if (inf == null)
+ throw new IOException("stream closed");
+ return inf.finished() ? 0 : 1;
+ }
+
+ /**
+ * Closes the input stream
+ */
+ public synchronized void close() throws IOException
+ {
+ if (in != null)
+ in.close();
+ in = null;
+ }
+
+ /**
+ * Fills the buffer with more data to decompress.
+ */
+ protected void fill() throws IOException
+ {
+ if (in == null)
+ throw new ZipException ("InflaterInputStream is closed");
+
+ len = in.read(buf, 0, buf.length);
+
+ if (len < 0)
+ throw new ZipException("Deflated stream ends early.");
+
+ inf.setInput(buf, 0, len);
+ }
+
+ /**
+ * Reads one byte of decompressed data.
+ *
+ * The byte is in the lower 8 bits of the int.
+ */
+ public int read() throws IOException
+ {
+ int nread = read(onebytebuffer, 0, 1);
+ if (nread > 0)
+ return onebytebuffer[0] & 0xff;
+ return -1;
+ }
+
+ /**
+ * Decompresses data into the byte array
+ *
+ * @param b the array to read and decompress data into
+ * @param off the offset indicating where the data should be placed
+ * @param len the number of bytes to decompress
+ */
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ if (inf == null)
+ throw new IOException("stream closed");
+ if (len == 0)
+ return 0;
+
+ int count = 0;
+ for (;;)
+ {
+
+ try
+ {
+ count = inf.inflate(b, off, len);
+ }
+ catch (DataFormatException dfe)
+ {
+ throw new ZipException(dfe.getMessage());
+ }
+
+ if (count > 0)
+ return count;
+
+ if (inf.needsDictionary()
+ | inf.finished())
+ return -1;
+ else if (inf.needsInput())
+ fill();
+ else
+ throw new InternalError("Don't know what to do");
+ }
+ }
+
+ /**
+ * Skip specified number of bytes of uncompressed data
+ *
+ * @param n number of bytes to skip
+ */
+ public long skip(long n) throws IOException
+ {
+ if (inf == null)
+ throw new IOException("stream closed");
+ if (n < 0)
+ throw new IllegalArgumentException();
+
+ if (n == 0)
+ return 0;
+
+ int buflen = (int) Math.min(n, 2048);
+ byte[] tmpbuf = new byte[buflen];
+
+ long skipped = 0L;
+ while (n > 0L)
+ {
+ int numread = read(tmpbuf, 0, buflen);
+ if (numread <= 0)
+ break;
+ n -= numread;
+ skipped += numread;
+ buflen = (int) Math.min(n, 2048);
+ }
+
+ return skipped;
+ }
+
+ public boolean markSupported()
+ {
+ return false;
+ }
+
+ public void mark(int readLimit)
+ {
+ }
+
+ public void reset() throws IOException
+ {
+ throw new IOException("reset not supported");
+ }
+}
Added: trunk/core/src/classpath/java/java/util/zip/ZipConstants.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/ZipConstants.java (rev 0)
+++ trunk/core/src/classpath/java/java/util/zip/ZipConstants.java 2009-04-03 05:36:41 UTC (rev 5212)
@@ -0,0 +1,94 @@
+/* java.util.zip.ZipConstants
+ Copyright (C) 2001, 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, pr...
[truncated message content] |