public class ChecksummedFile extends Object
Terminology:
| Constructor and Description |
|---|
ChecksummedFile(File referenceFile)
Construct a ChecksummedFile object.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public ChecksummedFile(File referenceFile)
referenceFile - public String calculateChecksum(ChecksumAlgorithm checksumAlgorithm) throws IOException
checksumAlgorithm - the algorithm to use.IOException - if unable to calculate the checksum.public File createChecksum(ChecksumAlgorithm checksumAlgorithm) throws IOException
checksumAlgorithm - the hash to use.IOException - if there was a problem either reading the referenceFile, or writing the checksum file.public File getChecksumFile(ChecksumAlgorithm checksumAlgorithm)
checksumAlgorithm - the hash that we are interested in.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.
algorithm - the algorithms to check for.IOException - if the reading of the checksumFile or the file it refers to fails.public boolean isValidChecksums(ChecksumAlgorithm[] algorithms)
algorithms - the algorithms to check for.public boolean fixChecksums(ChecksumAlgorithm[] algorithms)
algorithms - the hashes to check for.public String parseChecksum(String rawChecksumString, ChecksumAlgorithm expectedHash, String expectedPath) throws IOException
Validate the expected path, and expected checksum algorithm, then return the trimmed checksum hex string.
rawChecksumString - expectedHash - expectedPath - IOExceptionCopyright © 2006–2019 The Apache Software Foundation. All rights reserved.