Package nl.knaw.dans.bagit.creator
Class BagCreator
java.lang.Object
nl.knaw.dans.bagit.creator.BagCreator
Responsible for creating a bag in place.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Versionprivate static final Versionprivate static final org.slf4j.Loggerprivate static final ResourceBundle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BagbagInPlace(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) Creates a bag in place for version 0.97.static BagbagInPlace(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) Creates a bag in place for version 0.97.private static BagbagInPlace(Version version, Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) private static Map<Manifest,MessageDigest> calculatePayloadManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static Map<Manifest,MessageDigest> calculateTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static voidcreateBagitFile(Bag bag) static BagcreateDotBagit(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) Creates a basic(only required elements) .bagit bag in place.static BagcreateDotBagit(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) Creates a basic(only required elements) .bagit bag in place.private static voidcreateMetadataFile(Bag bag, Metadata metadata) private static voidcreatePayloadManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static voidcreateTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static voidmoveDataFiles(Path rootDir, Path dataDir, boolean includeHidden) private static voidmoveDataFilesIfNeeded(Bag bag, boolean includeHidden)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
messages
-
DATE_FORMAT
- See Also:
-
DOT_BAGIT_VERSION
-
LATEST_NON_DOT_BAGIT_VERSION
-
-
Constructor Details
-
BagCreator
private BagCreator()
-
-
Method Details
-
bagInPlace
public static Bag bagInPlace(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException Creates a bag in place for version 0.97. This method moves and creates files, thus if an error is thrown during operation it may leave the filesystem in an unknown state of transition. Thus this is not thread safe- Parameters:
root- the directory that will become the base of the bag and where to start searching for contentalgorithms- an collection ofSupportedAlgorithmimplementationsincludeHidden- to include hidden files when generating the bagit files, like the manifests- Returns:
- a
Bagobject representing the newly created bagit bag - Throws:
NoSuchAlgorithmException- ifMessageDigestcan't find the algorithmIOException- if there is a problem writing or moving file(s)
-
bagInPlace
public static Bag bagInPlace(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) throws NoSuchAlgorithmException, IOException Creates a bag in place for version 0.97. This method moves and creates files, thus if an error is thrown during operation it may leave the filesystem in an unknown state of transition. Thus this is not thread safe- Parameters:
root- the directory that will become the base of the bag and where to start searching for contentalgorithms- an collection ofSupportedAlgorithmimplementationsincludeHidden- to include hidden files when generating the bagit files, like the manifestsmetadata- the metadata to include when creating the bag. Payload-Oxum and Bagging-Date will be overwritten- Returns:
- a
Bagobject representing the newly created bagit bag - Throws:
NoSuchAlgorithmException- ifMessageDigestcan't find the algorithmIOException- if there is a problem writing or moving file(s)
-
createDotBagit
@Incubating public static Bag createDotBagit(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException Creates a basic(only required elements) .bagit bag in place. This creates files and directories, thus if an error is thrown during operation it may leave the filesystem in an unknown state of transition. Thus this is not thread safe- Parameters:
root- the directory that will become the base of the bag and where to start searching for contentalgorithms- an collection ofSupportedAlgorithmimplementationsincludeHidden- to include hidden files when generating the bagit files, like the manifests- Returns:
- a
Bagobject representing the newly created bagit bag - Throws:
NoSuchAlgorithmException- ifMessageDigestcan't find the algorithmIOException- if there is a problem writing files or .bagit directory
-
createDotBagit
@Incubating public static Bag createDotBagit(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) throws NoSuchAlgorithmException, IOException Creates a basic(only required elements) .bagit bag in place. This creates files and directories, thus if an error is thrown during operation it may leave the filesystem in an unknown state of transition. Thus this is not thread safe- Parameters:
root- the directory that will become the base of the bag and where to start searching for contentalgorithms- an collection ofSupportedAlgorithmimplementationsincludeHidden- to include hidden files when generating the bagit files, like the manifestsmetadata- the metadata to include when creating the bag. Payload-Oxum and Bagging-Date will be overwritten- Returns:
- a
Bagobject representing the newly created bagit bag - Throws:
NoSuchAlgorithmException- ifMessageDigestcan't find the algorithmIOException- if there is a problem writing files or .bagit directory
-
bagInPlace
private static Bag bagInPlace(Version version, Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
moveDataFilesIfNeeded
- Throws:
IOException
-
createBagitFile
- Throws:
IOException
-
moveDataFiles
private static void moveDataFiles(Path rootDir, Path dataDir, boolean includeHidden) throws IOException - Throws:
IOException
-
calculatePayloadManifests
private static Map<Manifest,MessageDigest> calculatePayloadManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
createPayloadManifests
private static void createPayloadManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
createMetadataFile
- Throws:
IOException
-
calculateTagManifests
private static Map<Manifest,MessageDigest> calculateTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-
createTagManifests
private static void createTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmExceptionIOException
-