1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util;
18
19 import java.io.InputStream;
20 import java.io.IOException;
21 import java.util.zip.Adler32;
22 import java.util.zip.CheckedInputStream;
23
24
25 /***
26 * implements checksum related utilities
27 *
28 * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
29 * @version $Id: ChecksumHelper.java 516448 2007-03-09 16:25:47Z ate $
30 */
31 public final class ChecksumHelper
32 {
33 public static long getChecksum(InputStream is)
34 {
35 CheckedInputStream cis = null;
36 long checksum = 0;
37 try
38 {
39 cis = new CheckedInputStream(is, new Adler32());
40 byte[] tempBuf = new byte[128];
41 while (cis.read(tempBuf) >= 0)
42 {
43 }
44 checksum = cis.getChecksum().getValue();
45 }
46 catch (IOException e)
47 {
48 checksum = 0;
49 }
50 finally
51 {
52 if (cis != null)
53 {
54 try
55 {
56 cis.close();
57 }
58 catch (IOException ioe)
59 {
60 }
61 }
62 }
63 return checksum;
64 }
65 }
66