home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / CRC32.java < prev    next >
Text File  |  1997-05-20  |  2KB  |  78 lines

  1. /*
  2.  * @(#)CRC32.java    1.11 97/01/27
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.util.zip;
  24.  
  25. /**
  26.  * A class that can be used to compute the CRC-32 of a data stream.
  27.  *
  28.  * @see        Checksum
  29.  * @version     1.11, 01/27/97
  30.  * @author     David Connelly
  31.  */
  32. public
  33. class CRC32 implements Checksum {
  34.     private int crc;
  35.  
  36.     /*
  37.      * Loads the ZLIB library.
  38.      */
  39.     static {
  40.     System.loadLibrary("zip");
  41.     }
  42.  
  43.     /**
  44.      * Updates CRC-32 with specified byte.
  45.      */
  46.     public void update(int b) {
  47.     update1(b);
  48.     }
  49.  
  50.     /**
  51.      * Updates CRC-32 with specified array of bytes.
  52.      */
  53.     public native void update(byte[] b, int off, int len);
  54.  
  55.     /**
  56.      * Updates CRC-32 with specified array of bytes.
  57.      */
  58.     public void update(byte[] b) {
  59.     update(b, 0, b.length);
  60.     }
  61.  
  62.     /**
  63.      * Resets CRC-32 to initial value.
  64.      */
  65.     public void reset() {
  66.     crc = 0;
  67.     }
  68.  
  69.     /**
  70.      * Returns CRC-32 value.
  71.      */
  72.     public long getValue() {
  73.     return (long)crc & 0xffffffffL;
  74.     }
  75.  
  76.     private native void update1(int b);
  77. }
  78.