01: /*
02: * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
10: *
11: * This code is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * version 2 for more details (a copy is included in the LICENSE file that
15: * accompanied this code).
16: *
17: * You should have received a copy of the GNU General Public License version
18: * 2 along with this work; if not, write to the Free Software Foundation,
19: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.tools.javazic;
27:
28: import java.util.zip.CRC32;
29:
30: /**
31: * Checksum provides methods for calculating a CRC32 value for a
32: * transitions table.
33: *
34: * @since 1.4
35: */
36: public class Checksum extends CRC32 {
37: /**
38: * Updates the CRC32 value from each byte of the given int
39: * value. The bytes are used in the big endian order.
40: * @param val the int value
41: */
42: public void update(int val) {
43: byte[] b = new byte[4];
44: b[0] = (byte) ((val >>> 24) & 0xff);
45: b[1] = (byte) ((val >>> 16) & 0xff);
46: b[2] = (byte) ((val >>> 8) & 0xff);
47: b[3] = (byte) (val & 0xff);
48: update(b);
49: }
50:
51: /**
52: * Updates the CRC32 value from each byte of the given long
53: * value. The bytes are used in the big endian order.
54: * @param val the long value
55: */
56: void update(long val) {
57: byte[] b = new byte[8];
58: b[0] = (byte) ((val >>> 56) & 0xff);
59: b[1] = (byte) ((val >>> 48) & 0xff);
60: b[2] = (byte) ((val >>> 40) & 0xff);
61: b[3] = (byte) ((val >>> 32) & 0xff);
62: b[4] = (byte) ((val >>> 24) & 0xff);
63: b[5] = (byte) ((val >>> 16) & 0xff);
64: b[6] = (byte) ((val >>> 8) & 0xff);
65: b[7] = (byte) (val & 0xff);
66: update(b);
67: }
68: }
|