1 7 8 package java.util.zip; 9 10 17 public 18 class CRC32 implements Checksum { 19 private int crc; 20 21 24 public CRC32() { 25 } 26 27 28 31 public void update(int b) { 32 crc = update(crc, b); 33 } 34 35 38 public void update(byte[] b, int off, int len) { 39 if (b == null) { 40 throw new NullPointerException (); 41 } 42 if (off < 0 || len < 0 || off > b.length - len) { 43 throw new ArrayIndexOutOfBoundsException (); 44 } 45 crc = updateBytes(crc, b, off, len); 46 } 47 48 53 public void update(byte[] b) { 54 crc = updateBytes(crc, b, 0, b.length); 55 } 56 57 60 public void reset() { 61 crc = 0; 62 } 63 64 67 public long getValue() { 68 return (long)crc & 0xffffffffL; 69 } 70 71 private native static int update(int crc, int b); 72 private native static int updateBytes(int crc, byte[] b, int off, int len); 73 } 74 | Popular Tags |