source: osm/applications/editors/josm/plugins/opendata/includes/org/j7zip/Common/CRC.java

Last change on this file was 36483, checked in by stoecker, 50 minutes ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1package org.j7zip.Common;
2
3public class CRC {
4 static public int[] Table = new int[256];
5
6 static
7 {
8 for (int i = 0; i < 256; i++) {
9 int r = i;
10 for (int j = 0; j < 8; j++)
11 if ((r & 1) != 0)
12 r = (r >>> 1) ^ 0xEDB88320;
13 else
14 r >>>= 1;
15 Table[i] = r;
16 }
17 }
18
19 int _value = -1;
20
21 public void Init() {
22 _value = -1;
23 }
24
25 public void UpdateByte(int b) {
26 _value = Table[(_value ^ b) & 0xFF] ^ (_value >>> 8);
27 }
28
29 public void UpdateUInt32(int v) {
30 for (int i = 0; i < 4; i++)
31 UpdateByte((v >> (8 * i)) & 0xFF );
32 }
33
34 public void UpdateUInt64(long v) {
35 for (int i = 0; i < 8; i++)
36 UpdateByte((int)((v >> (8 * i))) & 0xFF);
37 }
38
39 public int GetDigest() {
40 return _value ^ (-1);
41 }
42
43 public void Update(byte[] data, int size) {
44 for (int i = 0; i < size; i++)
45 _value = Table[(_value ^ data[i]) & 0xFF] ^ (_value >>> 8);
46 }
47
48 public void Update(byte[] data, int offset, int size) {
49 for (int i = 0; i < size; i++)
50 _value = Table[(_value ^ data[offset + i]) & 0xFF] ^ (_value >>> 8);
51 }
52
53 public static int CalculateDigest(byte [] data, int size) {
54 CRC crc = new CRC();
55 crc.Update(data, size);
56 return crc.GetDigest();
57 }
58
59 static public boolean VerifyDigest(int digest, byte [] data, int size) {
60 return (CalculateDigest(data, size) == digest);
61 }
62}
Note: See TracBrowser for help on using the repository browser.