KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ant > task > ShowCRCTask


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.ant.task;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Task;
28 import org.netbeans.spi.project.support.ant.CRC32Calculator;
29
30 /**
31  * Ant task to show CRCs of files such as <samp>build.xml</samp> as
32  * computed by {@link GeneratedFilesHelper}.
33  * @author Jesse Glick
34  */

35 public final class ShowCRCTask extends Task {
36
37     private File JavaDoc f;
38     public void setFile(File JavaDoc f) {
39         this.f = f;
40     }
41     
42     /** Standard constructor. */
43     public ShowCRCTask() {}
44     
45     public void execute() throws BuildException {
46         if (f == null) {
47             throw new BuildException("No 'file' attr");
48         }
49         try {
50             InputStream JavaDoc is = new FileInputStream JavaDoc(f);
51             try {
52                 String JavaDoc crc = CRC32Calculator.computeCrc32(is);
53                 log("CRC32 for " + f + ": " + crc);
54             } finally {
55                 is.close();
56             }
57         } catch (IOException JavaDoc e) {
58             throw new BuildException(e, getLocation());
59         }
60     }
61     
62 }
63
Popular Tags