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
Modifier and TypeFieldDescriptionprivate static final String
private static final Version
private static final Version
private static final org.slf4j.Logger
private static final ResourceBundle
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Bag
bagInPlace
(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) Creates a bag in place for version 0.97.static Bag
bagInPlace
(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) Creates a bag in place for version 0.97.private static Bag
bagInPlace
(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 void
createBagitFile
(Bag bag) static Bag
createDotBagit
(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) Creates a basic(only required elements) .bagit bag in place.static Bag
createDotBagit
(Path root, Collection<SupportedAlgorithm> algorithms, boolean includeHidden, Metadata metadata) Creates a basic(only required elements) .bagit bag in place.private static void
createMetadataFile
(Bag bag, Metadata metadata) private static void
createPayloadManifests
(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static void
createTagManifests
(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) private static void
moveDataFiles
(Path rootDir, Path dataDir, boolean includeHidden) private static void
moveDataFilesIfNeeded
(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 ofSupportedAlgorithm
implementationsincludeHidden
- to include hidden files when generating the bagit files, like the manifests- Returns:
- a
Bag
object representing the newly created bagit bag - Throws:
NoSuchAlgorithmException
- ifMessageDigest
can'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 ofSupportedAlgorithm
implementationsincludeHidden
- 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
Bag
object representing the newly created bagit bag - Throws:
NoSuchAlgorithmException
- ifMessageDigest
can'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 ofSupportedAlgorithm
implementationsincludeHidden
- to include hidden files when generating the bagit files, like the manifests- Returns:
- a
Bag
object representing the newly created bagit bag - Throws:
NoSuchAlgorithmException
- ifMessageDigest
can'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 ofSupportedAlgorithm
implementationsincludeHidden
- 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
Bag
object representing the newly created bagit bag - Throws:
NoSuchAlgorithmException
- ifMessageDigest
can'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:
NoSuchAlgorithmException
IOException
-
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:
NoSuchAlgorithmException
IOException
-
createPayloadManifests
private static void createPayloadManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmException
IOException
-
createMetadataFile
- Throws:
IOException
-
calculateTagManifests
private static Map<Manifest,MessageDigest> calculateTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmException
IOException
-
createTagManifests
private static void createTagManifests(Bag bag, Collection<SupportedAlgorithm> algorithms, boolean includeHidden) throws NoSuchAlgorithmException, IOException - Throws:
NoSuchAlgorithmException
IOException
-