Package nl.knaw.dans.bagit.verify
Class BagVerifier
java.lang.Object
nl.knaw.dans.bagit.verify.BagVerifier
- All Implemented Interfaces:
AutoCloseable
Responsible for verifying if a bag is valid, complete
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ExecutorService
private static final org.slf4j.Logger
private final ManifestVerifier
private static final ResourceBundle
-
Constructor Summary
ConstructorDescriptionCreate a BagVerifier with a cached thread pool and aStandardBagitAlgorithmNameToSupportedAlgorithmMapping
BagVerifier
(ExecutorService executor) Create a BagVerifier with a custom thread pool and aStandardBagitAlgorithmNameToSupportedAlgorithmMapping
BagVerifier
(ExecutorService executor, BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping) Create a BagVerifier with a custom thread pool and a custom mappingBagVerifier
(BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping) Create a BagVerifier with a cached thread pool and a custom mapping -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
canQuickVerify
(Bag bag) Determine if we can quickly verify by comparing the number of files and the total number of bytes expected(package private) void
checkHashes
(Manifest manifest) void
close()
void
isComplete
(Bag bag, boolean ignoreHiddenFiles) See https://tools.ietf.org/html/draft-kunze-bagit-13#section-3
A bag is complete if
every element is present every file in the payload manifest(s) are present every file in the tag manifest(s) are present.void
See https://tools.ietf.org/html/draft-kunze-bagit-13#section-3
A bag is valid if the bag is complete and every checksum has been verified against the contents of its corresponding file.static void
quicklyVerify
(Bag bag) Quickly verify by comparing the number of files and the total number of bytes expected
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
messages
-
manifestVerifier
-
executor
-
-
Constructor Details
-
BagVerifier
public BagVerifier()Create a BagVerifier with a cached thread pool and aStandardBagitAlgorithmNameToSupportedAlgorithmMapping
-
BagVerifier
Create a BagVerifier with a cached thread pool and a custom mapping- Parameters:
nameMapping
- the mapping between BagIt algorithm name and the java supported algorithm
-
BagVerifier
Create a BagVerifier with a custom thread pool and aStandardBagitAlgorithmNameToSupportedAlgorithmMapping
- Parameters:
executor
- the thread pool to use when doing work
-
BagVerifier
public BagVerifier(ExecutorService executor, BagitAlgorithmNameToSupportedAlgorithmMapping nameMapping) Create a BagVerifier with a custom thread pool and a custom mapping- Parameters:
nameMapping
- the mapping between BagIt algorithm name and the java supported algorithmexecutor
- the thread pool to use when doing work
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
SecurityException
-
canQuickVerify
Determine if we can quickly verify by comparing the number of files and the total number of bytes expected- Parameters:
bag
- theBag
object you wish to check- Returns:
- true if the bag can be quickly verified
-
quicklyVerify
Quickly verify by comparing the number of files and the total number of bytes expected- Parameters:
bag
- the bag to verify by payload-oxum- Throws:
IOException
- if there is an error reading a fileInvalidPayloadOxumException
- if either the total bytes or the number of files calculated for the payload directory of the bag is different than the supplied valuesPayloadOxumDoesNotExistException
- if the bag does not contain a payload-oxum. To check, runcanQuickVerify(nl.knaw.dans.bagit.domain.Bag)
-
isValid
public void isValid(Bag bag, boolean ignoreHiddenFiles) throws IOException, FileNotInManifestException, MissingPayloadManifestException, MissingBagitFileException, MissingPayloadDirectoryException, FileNotInPayloadDirectoryException, InterruptedException, MaliciousPathException, CorruptChecksumException, VerificationException, UnsupportedAlgorithmException, InvalidBagitFileFormatException See https://tools.ietf.org/html/draft-kunze-bagit-13#section-3
A bag is valid if the bag is complete and every checksum has been verified against the contents of its corresponding file.- Parameters:
bag
- theBag
object to checkignoreHiddenFiles
- ignore hidden files unless explicitly listed in manifest(s)- Throws:
CorruptChecksumException
- when the computed hash doesn't match given hashIOException
- if there was an error with the fileFileNotInManifestException
- if a file is found in the payload directory but not in manifest(s)MissingPayloadManifestException
- if there is not at least one payload manifestMissingBagitFileException
- if there is no bagit.txt fileMissingPayloadDirectoryException
- if there is no /data directoryFileNotInPayloadDirectoryException
- if a manifest lists a file but it is not in the payload directoryInterruptedException
- if the threads are interrupted when checking if all files are listed in manifest(s)MaliciousPathException
- if there is path that is referenced in the manifest that is outside the bag root directoryVerificationException
- some other exception happened during processing so capture it here.UnsupportedAlgorithmException
- if the manifest uses a algorithm that isn't supportedInvalidBagitFileFormatException
- if the manifest is not formatted properly
-
checkHashes
void checkHashes(Manifest manifest) throws CorruptChecksumException, InterruptedException, VerificationException -
isComplete
public void isComplete(Bag bag, boolean ignoreHiddenFiles) throws IOException, MissingPayloadManifestException, MissingBagitFileException, MissingPayloadDirectoryException, FileNotInPayloadDirectoryException, InterruptedException, MaliciousPathException, UnsupportedAlgorithmException, InvalidBagitFileFormatException See https://tools.ietf.org/html/draft-kunze-bagit-13#section-3
A bag is complete if
- every element is present
- every file in the payload manifest(s) are present
- every file in the tag manifest(s) are present. Tag files not listed in a tag manifest may be present.
- every file in the data directory must be listed in at least one payload manifest
- each element must comply with the bagit spec
- Parameters:
bag
- theBag
object to checkignoreHiddenFiles
- ignore hidden files unless explicitly listed in manifest(s)- Throws:
IOException
- if there was an error with the fileMissingPayloadManifestException
- if there is not at least one payload manifestMissingBagitFileException
- if there is no bagit.txt fileMissingPayloadDirectoryException
- if there is no /data directoryFileNotInPayloadDirectoryException
- if a manifest lists a file but it is not in the payload directoryInterruptedException
- if the threads are interrupted when checking if all files are listed in manifest(s)MaliciousPathException
- if there is path that is referenced in the manifest that is outside the bag root directoryUnsupportedAlgorithmException
- if the manifest uses a algorithm that isn't supportedInvalidBagitFileFormatException
- if the manifest is not formatted properly
-
getExecutor
-
getManifestVerifier
-