public class ChecksummedFile extends Object
Terminology:
Constructor and Description |
---|
ChecksummedFile(Path referenceFile)
Construct a ChecksummedFile object.
|
Modifier and Type | Method and Description |
---|---|
String |
calculateChecksum(ChecksumAlgorithm checksumAlgorithm)
Calculate the checksum based on a given checksum.
|
UpdateStatusList |
fixChecksum(ChecksumAlgorithm algorithm) |
UpdateStatusList |
fixChecksums(List<ChecksumAlgorithm> algorithms)
Writes a checksum file, if it does not exist or if it exists and has a different
checksum value.
|
Path |
getChecksumFile(ChecksumAlgorithm checksumAlgorithm)
Get the checksum file for the reference file and hash.
|
static ChecksumReference |
getFromChecksumFile(Path checksumFile) |
Path |
getReferenceFile() |
boolean |
isValidChecksum(ChecksumAlgorithm algorithm)
Given a checksum file, check to see if the file it represents is valid according to the checksum.
|
boolean |
isValidChecksum(ChecksumAlgorithm algorithm,
boolean throwExceptions) |
boolean |
isValidChecksums(List<ChecksumAlgorithm> algorithms)
Of any checksum files present, validate that the reference file conforms
the to the checksum.
|
boolean |
isValidChecksums(List<ChecksumAlgorithm> algorithms,
boolean throwExceptions)
Checks if the checksum files are valid for the referenced file.
|
String |
parseChecksum(Path checksumFile,
ChecksumAlgorithm checksumAlgorithm,
String fileName,
Charset encoding)
Parse a checksum string.
|
ChecksumFileContent |
parseChecksumFile(Path checksumFile,
ChecksumAlgorithm checksumAlgorithm,
Charset encoding) |
Path |
writeFile(ChecksumAlgorithm checksumAlgorithm)
Writes a checksum file for the referenceFile.
|
public ChecksummedFile(Path referenceFile)
referenceFile
- public static ChecksumReference getFromChecksumFile(Path checksumFile)
public String calculateChecksum(ChecksumAlgorithm checksumAlgorithm) throws IOException
checksumAlgorithm
- the algorithm to use.IOException
- if unable to calculate the checksum.public Path writeFile(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 Path getChecksumFile(ChecksumAlgorithm checksumAlgorithm)
checksumAlgorithm
- the hash that we are interested in.public boolean isValidChecksum(ChecksumAlgorithm algorithm) throws ChecksumValidationException
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.ChecksumValidationException
public boolean isValidChecksum(ChecksumAlgorithm algorithm, boolean throwExceptions) throws ChecksumValidationException
ChecksumValidationException
public boolean isValidChecksums(List<ChecksumAlgorithm> algorithms) throws ChecksumValidationException
algorithms
- the algorithms to check for.ChecksumValidationException
public boolean isValidChecksums(List<ChecksumAlgorithm> algorithms, boolean throwExceptions) throws ChecksumValidationException
algorithms
- The algorithms to verifythrowExceptions
- If true, exceptions will be thrown, otherwise false will be returned, if a exception occurred.ChecksumValidationException
public Path getReferenceFile()
public UpdateStatusList fixChecksum(ChecksumAlgorithm algorithm)
public UpdateStatusList fixChecksums(List<ChecksumAlgorithm> algorithms)
algorithms
- the hashes to check for.public String parseChecksum(Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding) throws ChecksumValidationException
Validate the expected path, and expected checksum algorithm, then return the trimmed checksum hex string.
checksumFile
- The file where the checksum is storedchecksumAlgorithm
- The checksum algorithm to checkfileName
- The filename of the reference fileIOException
ChecksumValidationException
public ChecksumFileContent parseChecksumFile(Path checksumFile, ChecksumAlgorithm checksumAlgorithm, Charset encoding)
Copyright © 2006–2019 The Apache Software Foundation. All rights reserved.