|
From: <chr...@us...> - 2009-03-25 05:00:06
|
Revision: 5151
http://jnode.svn.sourceforge.net/jnode/?rev=5151&view=rev
Author: chrisboertien
Date: 2009-03-25 04:59:56 +0000 (Wed, 25 Mar 2009)
Log Message:
-----------
Impelemntation of java.util.zip checksums
Added 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/Checksum.java
trunk/core/src/openjdk/vm/java/util/zip/
trunk/core/src/openjdk/vm/java/util/zip/NativeAdler32.java
trunk/core/src/openjdk/vm/java/util/zip/NativeCRC32.java
Removed 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/Checksum.java
Deleted: trunk/core/src/classpath/java/java/util/zip/Adler32.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/Adler32.java 2009-03-24 14:08:37 UTC (rev 5150)
+++ trunk/core/src/classpath/java/java/util/zip/Adler32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -1,205 +0,0 @@
-/* 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;
- }
-}
Deleted: trunk/core/src/classpath/java/java/util/zip/CRC32.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/CRC32.java 2009-03-24 14:08:37 UTC (rev 5150)
+++ trunk/core/src/classpath/java/java/util/zip/CRC32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -1,132 +0,0 @@
-/* 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); }
-}
Deleted: trunk/core/src/classpath/java/java/util/zip/Checksum.java
===================================================================
--- trunk/core/src/classpath/java/java/util/zip/Checksum.java 2009-03-24 14:08:37 UTC (rev 5150)
+++ trunk/core/src/classpath/java/java/util/zip/Checksum.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -1,86 +0,0 @@
-/* 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/openjdk/java/java/util/zip/Adler32.java
===================================================================
--- trunk/core/src/openjdk/java/java/util/zip/Adler32.java (rev 0)
+++ trunk/core/src/openjdk/java/java/util/zip/Adler32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -0,0 +1,93 @@
+/*
+ * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.util.zip;
+
+/**
+ * A class that can be used to compute the Adler-32 checksum of a data
+ * stream. An Adler-32 checksum is almost as reliable as a CRC-32 but
+ * can be computed much faster.
+ *
+ * @see Checksum
+ * @author David Connelly
+ */
+public
+class Adler32 implements Checksum {
+ private int adler = 1;
+
+ /**
+ * Creates a new Adler32 object.
+ */
+ public Adler32() {
+ }
+
+
+ /**
+ * Updates checksum with specified byte.
+ *
+ * @param b an array of bytes
+ */
+ public void update(int b) {
+ adler = update(adler, b);
+ }
+
+ /**
+ * Updates checksum with specified array of bytes.
+ */
+ public void update(byte[] b, int off, int len) {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ adler = updateBytes(adler, b, off, len);
+ }
+
+ /**
+ * Updates checksum with specified array of bytes.
+ */
+ public void update(byte[] b) {
+ adler = updateBytes(adler, b, 0, b.length);
+ }
+
+ /**
+ * Resets checksum to initial value.
+ */
+ public void reset() {
+ adler = 1;
+ }
+
+ /**
+ * Returns checksum value.
+ */
+ public long getValue() {
+ return (long)adler & 0xffffffffL;
+ }
+
+ private native static int update(int adler, int b);
+ private native static int updateBytes(int adler, byte[] b, int off,
+ int len);
+}
Added: trunk/core/src/openjdk/java/java/util/zip/CRC32.java
===================================================================
--- trunk/core/src/openjdk/java/java/util/zip/CRC32.java (rev 0)
+++ trunk/core/src/openjdk/java/java/util/zip/CRC32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -0,0 +1,90 @@
+/*
+ * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.util.zip;
+
+/**
+ * A class that can be used to compute the CRC-32 of a data stream.
+ *
+ * @see Checksum
+ * @author David Connelly
+ */
+public
+class CRC32 implements Checksum {
+ private int crc;
+
+ /**
+ * Creates a new CRC32 object.
+ */
+ public CRC32() {
+ }
+
+
+ /**
+ * Updates CRC-32 with specified byte.
+ */
+ public void update(int b) {
+ crc = update(crc, b);
+ }
+
+ /**
+ * Updates CRC-32 with specified array of bytes.
+ */
+ public void update(byte[] b, int off, int len) {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+ if (off < 0 || len < 0 || off > b.length - len) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ crc = updateBytes(crc, b, off, len);
+ }
+
+ /**
+ * Updates checksum with specified array of bytes.
+ *
+ * @param b the array of bytes to update the checksum with
+ */
+ public void update(byte[] b) {
+ crc = updateBytes(crc, b, 0, b.length);
+ }
+
+ /**
+ * Resets CRC-32 to initial value.
+ */
+ public void reset() {
+ crc = 0;
+ }
+
+ /**
+ * Returns CRC-32 value.
+ */
+ public long getValue() {
+ return (long)crc & 0xffffffffL;
+ }
+
+ private native static int update(int crc, int b);
+ private native static int updateBytes(int crc, byte[] b, int off, int len);
+}
Added: trunk/core/src/openjdk/java/java/util/zip/Checksum.java
===================================================================
--- trunk/core/src/openjdk/java/java/util/zip/Checksum.java (rev 0)
+++ trunk/core/src/openjdk/java/java/util/zip/Checksum.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.util.zip;
+
+/**
+ * An interface representing a data checksum.
+ *
+ * @author David Connelly
+ */
+public
+interface Checksum {
+ /**
+ * Updates the current checksum with the specified byte.
+ *
+ * @param b the byte to update the checksum with
+ */
+ public void update(int b);
+
+ /**
+ * Updates the current checksum with the specified array of bytes.
+ * @param b the byte array to update the checksum with
+ * @param off the start offset of the data
+ * @param len the number of bytes to use for the update
+ */
+ public void update(byte[] b, int off, int len);
+
+ /**
+ * Returns the current checksum value.
+ * @return the current checksum value
+ */
+ public long getValue();
+
+ /**
+ * Resets the checksum to its initial value.
+ */
+ public void reset();
+}
Added: trunk/core/src/openjdk/vm/java/util/zip/NativeAdler32.java
===================================================================
--- trunk/core/src/openjdk/vm/java/util/zip/NativeAdler32.java (rev 0)
+++ trunk/core/src/openjdk/vm/java/util/zip/NativeAdler32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -0,0 +1,61 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package java.util.zip;
+
+/**
+ * Implementation of java.util.zip.Adler32 native methods.
+ *
+ * @author Chris Boertien
+ * @date Mar 24, 2009
+ */
+
+public class NativeAdler32 {
+
+ private static int update( int adler , int b ) {
+ int s1 = adler & 0xffff;
+ int s2 = adler >>> 16;
+
+ s1 = (s1 + (b & 0xFF)) % 65521;
+ s2 = (s1 + s2) % 65521;
+
+ return (s2 << 16) + s1;
+ }
+
+ private static int updateBytes( int adler , byte[] b , int off , int len ) {
+ int n;
+ int s1 = adler & 0xffff;
+ int s2 = adler >>> 16;
+
+ while (len > 0) {
+ n = 3800;
+ if (n > len) n = len;
+ len -= n;
+ while (--n >= 0) {
+ s1 = s1 + (b[off++] & 0xFF);
+ s2 = s2 + s1;
+ }
+ s1 %= 65521;
+ s2 %= 65521;
+ }
+
+ return (s2 << 16) | s1;
+ }
+}
Added: trunk/core/src/openjdk/vm/java/util/zip/NativeCRC32.java
===================================================================
--- trunk/core/src/openjdk/vm/java/util/zip/NativeCRC32.java (rev 0)
+++ trunk/core/src/openjdk/vm/java/util/zip/NativeCRC32.java 2009-03-25 04:59:56 UTC (rev 5151)
@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2009 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package java.util.zip;
+
+/**
+ * Implementation of java.util.zip.CRC32 native methods.
+ *
+ * @author Chris Boertien
+ * @date Mar 24, 2009
+ */
+public class NativeCRC32 {
+
+ /** The fast CRC table. Computed once when the CRC32 class is loaded. */
+ private static final int[] fastCRCTable = fastCRCTable();
+
+ /** Make the table for a fast CRC. */
+ private static int[] fastCRCTable() {
+ 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;
+ }
+
+ private static int update( int crc , int b ) {
+ int c = ~crc;
+ c = fastCRCTable[(c^b) & 0xff] ^ (c >>> 8);
+ return ~c;
+ }
+
+ private static int updateBytes( int crc , byte[] b , int off , int len ) {
+ int c = ~crc;
+ while (--len >= 0)
+ c = fastCRCTable[(c ^ b[off++]) & 0xff] ^ (c >>> 8);
+ return ~c;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|