Class BagItWriter

java.lang.Object
io.goobi.viewer.model.export.bagit.BagItWriter

public final class BagItWriter extends Object
Minimal, dependency-free writer for BagIt bags, serialized as a ZIP.

The caller assembles the payload into <bagRoot>/data/… (arbitrary sub-directory structure) and then calls writeZippedBag(Path, Path, Map, Integer). This class then:

  1. writes bagit.txt (version + encoding declaration),
  2. computes a SHA-512 digest for every payload file and writes manifest-sha512.txt,
  3. writes bag-info.txt (the supplied metadata plus a computed Payload-Oxum and Bag-Size),
  4. writes tagmanifest-sha512.txt over the tag files,
  5. serializes the whole bag into a ZIP whose single top-level directory is the bag name.

All file I/O is streamed, so bags containing large binary media are handled without loading files into memory. Payload checksums are computed in a single pass while reading each file.

  • Field Details

    • BAGIT_VERSION

      public static final String BAGIT_VERSION
      BagIt version declared in bagit.txt.
      See Also:
    • ALGORITHM

      public static final String ALGORITHM
      Checksum algorithm used for both the payload manifest and the tag manifest.
      See Also:
  • Method Details

    • writeZippedBag

      public static void writeZippedBag(Path bagRoot, Path targetZip, Map<String,String> bagInfo, Integer compressionLevel) throws IOException
      Finalizes the bag rooted at bagRoot (which must already contain a populated data/ directory) by writing its tag files and manifests, then serializes it into targetZip.
      Parameters:
      bagRoot - the bag root directory containing a data/ payload sub-directory
      targetZip - the ZIP file to create (parent directories must exist)
      bagInfo - ordered metadata entries for bag-info.txt (e.g. Source-Organization, External-Description); may be null
      compressionLevel - ZIP compression level 0-9, or null for the default; use a low value for already-compressed media payloads
      Throws:
      IOException - on any I/O error