Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Checksum

extends MatchingTask
implements Condition
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.condition.Condition
Imports
java.io.BufferedReader, .File, .FileReader, .IOException, .InputStream, .OutputStream, java.nio.file.Files, java.security.DigestInputStream, .MessageDigest, .NoSuchAlgorithmException, .NoSuchProviderException, java.text.MessageFormat, .ParseException, java.util.Arrays, .Comparator, .HashMap, .Hashtable, .Map, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.taskdefs.condition.Condition, org.apache.tools.ant.types.EnumeratedAttribute, .FileSet, .Resource, .ResourceCollection, org.apache.tools.ant.types.resources.FileProvider, .Restrict, .Union, org.apache.tools.ant.types.resources.selectors.Type, org.apache.tools.ant.util.FileUtils

Used to create or verify file checksums.
Since
Ant 1.5

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
Checksum.FormatElement

Helper class for the format attribute.

Field Summary

Modifier and TypeField and Description
private String
algorithm

MessageDigest algorithm to be used.

private Map<File, byte[]>
allDigests

Holds checksums for all files (both calculated and cached on disk).

private static final int
private static final int
private File
file

File for which checksum is to be calculated.

private String
fileext

File Extension that is be to used to create or identify destination file

private boolean
forceOverwrite

Whether or not to create a new file.

private MessageFormat
format

Formatter for the checksum file.

private Hashtable<File, Object>
includeFileMap

Stores SourceFile, DestFile pairs and SourceFile, Property String pairs.

private boolean
isCondition

is this task being used as a nested condition element?

private MessageDigest
messageDigest

Message Digest instance

private static final int
private String
property

Holds generated checksum and gets set as a Project Property.

private String
provider

MessageDigest Algorithm provider

private int
readBufferSize

Size of the read buffer to use.

private Map<File, String>
relativeFilePaths

Holds relative file names for all files (always with a forward slash).

private Checksum.FileUnion
resources

Resource Collection.

private File
todir

Root directory in which the checksum files will be written.

private String
totalproperty

Property where totalChecksum gets set.

private String
verifyProperty

Contains the result of a checksum verification.

private static final int
Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
fileset

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(ResourceCollection
the ResourceCollection to add.
rc
)

Add a resource collection.

public void
addFileset(FileSet
a fileset of files to generate checksums for.
set
)

Files to generate checksums for.

private void
addToIncludeFileMap(File file)

Add key-value pair to the hashtable upon which to later operate upon.

private String
createDigestString(byte[] fileDigest)

public static byte[]

Returns:

the converted array of bytes
decodeHex
(char[]
an array of characters representing hexadecimal values
data
)

Converts an array of characters representing hexadecimal values into an array of bytes of those same values.

public boolean

Returns:

Returns true if the checksum verification test passed, false otherwise.
eval
()

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Calculate the checksum(s)
public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Calculate the checksum(s).
private boolean
generateChecksums()

Generate checksum(s) using the message digest created earlier.

private File
private String
private String
readChecksum(File f)

reads the checksum from a file using the specified format.

public void
setAlgorithm(String
a String value
algorithm
)

Specifies the algorithm to be used to compute the checksum.

public void
setFile(File
a File value
file
)

Sets the file for which the checksum is to be calculated.

public void
setFileext(String
a String value
fileext
)

Sets the file extension that is be to used to create or identify destination file.

public void
setForceOverwrite(boolean
a boolean value
forceOverwrite
)

Whether or not to overwrite existing file irrespective of whether it is newer than the source file.

public void
setFormat(Checksum.FormatElement
an enumerated value
e
)

Select the in/output pattern via a well know format name.

public void
setPattern(String
a String value
pattern
)

Specify the pattern to use as a MessageFormat pattern.

public void
setProperty(String
a String value
property
)

Sets the property to hold the generated checksum.

public void
setProvider(String
a String value
provider
)

Sets the MessageDigest algorithm provider to be used to calculate the checksum.

public void
setReadBufferSize(int
an int value
size
)

The size of the read buffer to use.

public void
setTodir(File
the directory to write to
todir
)

Sets the root directory where checksum files will be written/read

public void
setTotalproperty(String
a String value
totalproperty
)

Sets the property to hold the generated total checksum for all files.

public void
setVerifyproperty(String
a String value
verifyProperty
)

Sets the verify property.

private boolean
validateAndExecute()

Validate attributes and get down to business.

Inherited from org.apache.tools.ant.taskdefs.MatchingTask:
addaddAndaddContainsaddContainsRegexpaddCustomaddDateaddDependaddDepthaddDifferentaddFilenameaddMajorityaddModifiedaddNoneaddNotaddOraddPresentaddSelectoraddSizeaddTypeappendSelectorcreateExcludecreateExcludesFilecreateIncludecreateIncludesFilecreatePatternSetgetDirectoryScannergetImplicitFileSetgetSelectorshasSelectorsselectorCountselectorElementssetCaseSensitivesetDefaultexcludessetExcludessetExcludesfilesetFollowSymlinkssetIncludessetIncludesfilesetProjectXsetIgnoreXsetItems

Field Detail

algorithmback to summary
private String algorithm

MessageDigest algorithm to be used.

allDigestsback to summary
private Map<File, byte[]> allDigests

Holds checksums for all files (both calculated and cached on disk). Key: java.util.File (source file) Value: java.lang.String (digest)

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
BYTE_MASKback to summary
private static final int BYTE_MASK
fileback to summary
private File file

File for which checksum is to be calculated.

fileextback to summary
private String fileext

File Extension that is be to used to create or identify destination file

forceOverwriteback to summary
private boolean forceOverwrite

Whether or not to create a new file. Defaults to false.

formatback to summary
private MessageFormat format

Formatter for the checksum file.

includeFileMapback to summary
private Hashtable<File, Object> includeFileMap

Stores SourceFile, DestFile pairs and SourceFile, Property String pairs.

isConditionback to summary
private boolean isCondition

is this task being used as a nested condition element?

messageDigestback to summary
private MessageDigest messageDigest

Message Digest instance

NIBBLEback to summary
private static final int NIBBLE
propertyback to summary
private String property

Holds generated checksum and gets set as a Project Property.

providerback to summary
private String provider

MessageDigest Algorithm provider

readBufferSizeback to summary
private int readBufferSize

Size of the read buffer to use.

relativeFilePathsback to summary
private Map<File, String> relativeFilePaths

Holds relative file names for all files (always with a forward slash). This is used to calculate the total hash. Key: java.util.File (source file) Value: java.lang.String (relative file name)

resourcesback to summary
private Checksum.FileUnion resources

Resource Collection.

todirback to summary
private File todir

Root directory in which the checksum files will be written. If not specified, the checksum files will be written in the same directory as each file.

totalpropertyback to summary
private String totalproperty

Property where totalChecksum gets set.

verifyPropertyback to summary
private String verifyProperty

Contains the result of a checksum verification. ("true" or "false")

WORDback to summary
private static final int WORD

Constructor Detail

Checksumback to summary
public Checksum()

Method Detail

addback to summary
public void add(ResourceCollection rc)

Add a resource collection.

Parameters
rc:ResourceCollection

the ResourceCollection to add.

addFilesetback to summary
public void addFileset(FileSet set)

Files to generate checksums for.

Parameters
set:FileSet

a fileset of files to generate checksums for.

addToIncludeFileMapback to summary
private void addToIncludeFileMap(File file) throws BuildException

Add key-value pair to the hashtable upon which to later operate upon.

createDigestStringback to summary
private String createDigestString(byte[] fileDigest)
decodeHexback to summary
public static byte[] decodeHex(char[] data) throws BuildException

Converts an array of characters representing hexadecimal values into an array of bytes of those same values. The returned array will be half the length of the passed array, as it takes two characters to represent any given byte. An exception is thrown if the passed char array has an odd number of elements.

Note

This code is copied from jakarta-commons codec.

Parameters
data:char[]

an array of characters representing hexadecimal values

Returns:byte[]

the converted array of bytes

Exceptions
BuildException:
on error
evalback to summary
public boolean eval() throws BuildException

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Calculate the checksum(s)

Returns:boolean

Returns true if the checksum verification test passed, false otherwise.

Annotations
@Override
Exceptions
BuildException:
on error
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Calculate the checksum(s).

Annotations
@Override
Exceptions
BuildException:
on error
generateChecksumsback to summary
private boolean generateChecksums() throws BuildException

Generate checksum(s) using the message digest created earlier.

getChecksumFileback to summary
private File getChecksumFile(File file)
getRelativeFilePathback to summary
private String getRelativeFilePath(File f)
Since
Ant 1.8.2
readChecksumback to summary
private String readChecksum(File f)

reads the checksum from a file using the specified format.

Since
1.7
setAlgorithmback to summary
public void setAlgorithm(String algorithm)

Specifies the algorithm to be used to compute the checksum. Defaults to "MD5". Other popular algorithms like "SHA" may be used as well.

Parameters
algorithm:String

a String value

setFileback to summary
public void setFile(File file)

Sets the file for which the checksum is to be calculated.

Parameters
file:File

a File value

setFileextback to summary
public void setFileext(String fileext)

Sets the file extension that is be to used to create or identify destination file.

Parameters
fileext:String

a String value

setForceOverwriteback to summary
public void setForceOverwrite(boolean forceOverwrite)

Whether or not to overwrite existing file irrespective of whether it is newer than the source file. Defaults to false.

Parameters
forceOverwrite:boolean

a boolean value

setFormatback to summary
public void setFormat(Checksum.FormatElement e)

Select the in/output pattern via a well know format name.

Parameters
e:Checksum.FormatElement

an enumerated value

Since
1.7.0
setPatternback to summary
public void setPattern(String pattern)

Specify the pattern to use as a MessageFormat pattern.

{0} gets replaced by the checksum, {1} by the filename.

Parameters
pattern:String

a String value

Since
1.7.0
setPropertyback to summary
public void setProperty(String property)

Sets the property to hold the generated checksum.

Parameters
property:String

a String value

setProviderback to summary
public void setProvider(String provider)

Sets the MessageDigest algorithm provider to be used to calculate the checksum.

Parameters
provider:String

a String value

setReadBufferSizeback to summary
public void setReadBufferSize(int size)

The size of the read buffer to use.

Parameters
size:int

an int value

setTodirback to summary
public void setTodir(File todir)

Sets the root directory where checksum files will be written/read

Parameters
todir:File

the directory to write to

Since
Ant 1.6
setTotalpropertyback to summary
public void setTotalproperty(String totalproperty)

Sets the property to hold the generated total checksum for all files.

Parameters
totalproperty:String

a String value

Since
Ant 1.6
setVerifypropertyback to summary
public void setVerifyproperty(String verifyProperty)

Sets the verify property. This project property holds the result of a checksum verification - "true" or "false"

Parameters
verifyProperty:String

a String value

validateAndExecuteback to summary
private boolean validateAndExecute() throws BuildException

Validate attributes and get down to business.

org.apache.tools.ant.taskdefs back to summary

private Class Checksum.FileUnion

extends Restrict
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Union
u

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
add(ResourceCollection
the ResourceCollection to add.
rc
)

Overrides org.apache.tools.ant.types.resources.Restrict.add.

Add the ResourceCollection.
Inherited from org.apache.tools.ant.types.resources.Restrict:
adddieOnCircularReferenceisCacheisFilesystemOnlyiteratorsetCachesizetoString

Field Detail

uback to summary
private Union u

Constructor Detail

FileUnionback to summary
pack-priv FileUnion()

Method Detail

addback to summary
public void add(ResourceCollection rc)

Overrides org.apache.tools.ant.types.resources.Restrict.add.

Doc from org.apache.tools.ant.types.resources.Restrict.add.

Add the ResourceCollection.

Parameters
rc:ResourceCollection

the ResourceCollection to add.

Annotations
@Override
org.apache.tools.ant.taskdefs back to summary

public Class Checksum.FormatElement

extends EnumeratedAttribute
Class Inheritance

Helper class for the format attribute.
Since
1.7

Field Summary

Modifier and TypeField and Description
private static final String
private static HashMap<String, MessageFormat>
private static final String
private static final String
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Checksum.FormatElement

Returns:

the defaul value.
getDefault
()

Get the default value - CHECKSUM.

public MessageFormat

Returns:

a MessageFormat object.
getFormat
()

Convert this enumerated type to a MessageFormat.

public String[]

Returns:

an array of values.
getValues
()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Get the valid values.
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

CHECKSUMback to summary
private static final String CHECKSUM
formatMapback to summary
private static HashMap<String, MessageFormat> formatMap
MD5SUMback to summary
private static final String MD5SUM
SVFback to summary
private static final String SVF

Constructor Detail

FormatElementback to summary
public FormatElement()

Method Detail

getDefaultback to summary
public static Checksum.FormatElement getDefault()

Get the default value - CHECKSUM.

Returns:Checksum.FormatElement

the defaul value.

getFormatback to summary
public MessageFormat getFormat()

Convert this enumerated type to a MessageFormat.

Returns:MessageFormat

a MessageFormat object.

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Get the valid values.

Returns:String[]

an array of values.

Annotations
@Override