java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Ant arrow How to use Checksum task
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Checksum task E-mail
User Rating: / 9
PoorBest 

Checksum

Description

Generates checksum for files. This task can also be used to perform checksum verifications.

Note that many popular message digest functions - including MD5 and SHA-1 - have been broken recently. If you are going to use the task to create checksums used in an environment where security is important, please take some time to investigate the algorithms offered by your JCE provider. Note also that some JCE providers like the one by The Legion of the Bouncy Castle, the GNU project or the Technical University Graz offer more digest algorithms than those built-in into your JDK.

Parameters

Attribute Description Required
file The file to generate checksum for. One of either file or at least one nested fileset element.
todir The root directory where checksums should be written. No. If not specified, checksum files will be written to the same directory as the files themselves. since Ant 1.6
algorithm Specifies the algorithm to be used to compute the checksum. Defaults to "MD5". Other popular algorithms like "SHA" may be used as well. No
provider Specifies the provider of the algorithm. No
fileext The generated checksum file's name will be the original filename with the fileext added to it. Defaults to a "." and the algorithm name being used. No
property This attribute can mean two different things, it depends on the presence of the verifyproperty attribute.
If you don't set the verifyproperty attribute, property specifies the name of the property to be set with the generated checksum value.
If you set the verifyproperty attribute, property specifies the checksum you expect to be generated (the checksum itself, not a name of a property containing the checksum).
This cannot be specified when fileext is being used or when the number of files for which checksums is to be generated is greater than 1.
No
totalproperty If specified, this attribute specifies the name of the property that will hold a checksum of all the checksums and file paths. The individual checksums and the relative paths to the files within the filesets they are defined in will be used to compute this checksum. (The file separators in the paths will be converted to '/' before computation to ensure platform portability). since Ant 1.6 No
forceoverwrite Overwrite existing files even if the destination files are newer. Defaults to "no". No
verifyproperty Specifies the name of the property to be set with "true" or "false" depending upon whether the generated checksum matches the existing checksum. When this is set, the generated checksum is not written to a file or property, but rather, the content of the file or property is used to check against the generated checksum. No
readbuffersize The size of the buffer (in bytes) to use when reading a file. Defaults to "8192" - you may get a better performance on big files if you increase this value. No

Parameters specified as nested elements

fileset

FileSets are used to select files to generate checksums for.

Examples

Example 1

<checksum file="foo.bar"/>
Generates a MD5 checksum for foo.bar and stores the checksum in the destination file foo.bar.MD5. foo.bar.MD5 is overwritten only if foo.bar is newer than itself.

Example 2

<checksum file="foo.bar" forceOverwrite="yes"/>
Generates a MD5 checksum for foo.bar and stores the checksum in foo.bar.MD5. If foo.bar.MD5 already exists, it is overwritten.

Example 3

<checksum file="foo.bar" property="foobarMD5"/>
Generates a MD5 checksum for foo.bar and stores it in the Project Property foobarMD5.

Example 4

<checksum file="foo.bar" verifyProperty="isMD5ok"/>
Generates a MD5 checksum for foo.bar, compares it against foo.bar.MD5 and sets isMD5ok to either true or false, depending upon the result.

Example 5

<checksum file="foo.bar" algorithm="SHA" fileext="asc"/>
Generates a SHA checksum for foo.bar and stores the checksum in the destination file foo.bar.asc. foo.bar.asc is overwritten only if foo.bar is newer than itself.

Example 6

<checksum file="foo.bar" property="${md5}" verifyProperty="isEqual"/>
Generates a MD5 checksum for foo.bar, compares it against the value of the property md5, and sets isEqual to either true or false, depending upon the result.

Example 7

<checksum>
  <fileset dir=".">
    <include name="foo*"/>
  </fileset>
</checksum>

Works just like Example 1, but generates a .MD5 file for every file that begins with the name foo.

Example 8

<condition property="isChecksumEqual">
  <checksum>
    <fileset dir=".">
      <include name="foo.bar"/>

    </fileset>
  </checksum>
</condition>
Works like Example 4, but only sets isChecksumEqual to true, if the checksum matches - it will never be set to false. This example demonstrates use with the Condition task.

Note:

When working with more than one file, if condition and/or verifyproperty is used, the result will be true only if the checksums matched correctly for all files being considered.

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.