KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > MD5SumCalculator


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: MD5SumCalculator.java 154 2 août 06 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.net.URI JavaDoc;
27
28 import com.twmacinta.util.MD5;
29
30 /**
31  *
32  * @author ofabre - EBM Websourcing
33  *
34  */

35 public final class MD5SumCalculator {
36
37     private MD5SumCalculator() {
38         // do nothing
39
}
40
41     /**
42      * Calculate the MD5Sum of an archive
43      *
44      * @return the {@link String} hash code
45      * @throws PetalsRuntimeException
46      * if MD5Sum calculation fails
47      */

48     public static String JavaDoc calculateMD5Sum(URI JavaDoc archiveURI)
49         throws PetalsRuntimeException {
50
51         String JavaDoc hash = null;
52         try {
53             hash = MD5.asHex(MD5.getHash(new File JavaDoc(archiveURI)));
54         } catch (IOException JavaDoc e) {
55             String JavaDoc msg = "Error when calculating MD5 sum of the archive : "
56                     + archiveURI + ".";
57             throw new PetalsRuntimeException(msg, e);
58         }
59         return hash;
60     }
61
62 }
63
Popular Tags