org.apache.archiva.checksum
Class ChecksummedFile

java.lang.Object
  extended by org.apache.archiva.checksum.ChecksummedFile

public class ChecksummedFile
extends Object

ChecksummedFile

Terminology:
Checksum File
The file that contains the previously calculated checksum value for the reference file. This is a text file with the extension ".sha1" or ".md5", and contains a single entry consisting of an optional reference filename, and a checksum string.
Reference File
The file that is being referenced in the checksum file.


Constructor Summary
ChecksummedFile(File referenceFile)
          Construct a ChecksummedFile object.
 
Method Summary
 String calculateChecksum(ChecksumAlgorithm checksumAlgorithm)
          Calculate the checksum based on a given checksum.
 File createChecksum(ChecksumAlgorithm checksumAlgorithm)
          Creates a checksum file of the provided referenceFile.
 boolean fixChecksums(ChecksumAlgorithm[] algorithms)
          Fix or create checksum files for the reference file.
 File getChecksumFile(ChecksumAlgorithm checksumAlgorithm)
          Get the checksum file for the reference file and hash.
 boolean isValidChecksum(ChecksumAlgorithm algorithm)
           Given a checksum file, check to see if the file it represents is valid according to the checksum.
 boolean isValidChecksums(ChecksumAlgorithm[] algorithms)
          Of any checksum files present, validate that the reference file conforms the to the checksum.
 String parseChecksum(String rawChecksumString, ChecksumAlgorithm expectedHash, String expectedPath)
          Parse a checksum string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChecksummedFile

public ChecksummedFile(File referenceFile)
Construct a ChecksummedFile object.

Parameters:
referenceFile -
Method Detail

calculateChecksum

public String calculateChecksum(ChecksumAlgorithm checksumAlgorithm)
                         throws IOException
Calculate the checksum based on a given checksum.

Parameters:
checksumAlgorithm - the algorithm to use.
Returns:
the checksum string for the file.
Throws:
IOException - if unable to calculate the checksum.

createChecksum

public File createChecksum(ChecksumAlgorithm checksumAlgorithm)
                    throws IOException
Creates a checksum file of the provided referenceFile.

Parameters:
checksumAlgorithm - the hash to use.
Returns:
the checksum File that was created.
Throws:
IOException - if there was a problem either reading the referenceFile, or writing the checksum file.

getChecksumFile

public File getChecksumFile(ChecksumAlgorithm checksumAlgorithm)
Get the checksum file for the reference file and hash.

Parameters:
checksumAlgorithm - the hash that we are interested in.
Returns:
the checksum file to return

isValidChecksum

public boolean isValidChecksum(ChecksumAlgorithm algorithm)
                        throws IOException

Given a checksum file, check to see if the file it represents is valid according to the checksum.

NOTE: Only supports single file checksums of type MD5 or SHA1.

Parameters:
checksumFile - the algorithms to check for.
Returns:
true if the checksum is valid for the file it represents. or if the checksum file does not exist.
Throws:
IOException - if the reading of the checksumFile or the file it refers to fails.

isValidChecksums

public boolean isValidChecksums(ChecksumAlgorithm[] algorithms)
Of any checksum files present, validate that the reference file conforms the to the checksum.

Parameters:
algorithms - the algorithms to check for.
Returns:
true if the checksums report that the the reference file is valid, false if invalid.

fixChecksums

public boolean fixChecksums(ChecksumAlgorithm[] algorithms)
Fix or create checksum files for the reference file.

Parameters:
algorithms - the hashes to check for.
Returns:
true if checksums were created successfully.

parseChecksum

public String parseChecksum(String rawChecksumString,
                            ChecksumAlgorithm expectedHash,
                            String expectedPath)
                     throws IOException
Parse a checksum string.

Validate the expected path, and expected checksum algorithm, then return the trimmed checksum hex string.

Parameters:
rawChecksumString -
expectedHash -
expectedPath -
Returns:
Throws:
IOException


Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved.