java.lang.Object
org.odpi.openmetadata.adapters.connectors.surveyaction.seal.ContentSeal

public class ContentSeal extends Object
ContentSeal creates the manifest for sealed content and compares the content with its manifest later.

The members of sealed content are the regular files in the sealed directory and the directories beneath it, or the sealed file itself. Symbolic links are not followed and are not members. The manifest holds the relative path, size, last modified time and SHA-256 content hash of each member.

This class only reads the sealed content. The one file it writes is the manifest, and it refuses to write that inside the sealed content, or over an existing file.
  • Field Details

    • ALGORITHM

      public static final String ALGORITHM
      The algorithm used to hash the content of each member, and the manifest.
      See Also:
  • Method Details

    • hashFile

      public static String hashFile(File file) throws IOException
      Return the hash of the content of a file.
      Parameters:
      file - file to read
      Returns:
      hash in hexadecimal
      Throws:
      IOException - the file can not be read
    • createManifest

      public static SealManifest createManifest(File root, String sealedElementGUID, String rootPathName, String sealedBy, Date sealedTime) throws IOException
      Read every member of the content and return the manifest that describes it.
      Parameters:
      root - file or directory to seal
      sealedElementGUID - unique identifier of the element that describes the content
      rootPathName - path name of the content, as it is catalogued
      sealedBy - who, or what, is sealing the content
      sealedTime - when the content is sealed
      Returns:
      manifest
      Throws:
      IOException - a member can not be read - the content can not be sealed
    • writeManifest

      public static String writeManifest(SealManifest manifest, File manifestFile, File root) throws IOException
      Write a manifest to a new file. The file must not exist and must not be inside the sealed content.
      Parameters:
      manifest - manifest to write
      manifestFile - where to write it
      root - the sealed file or directory
      Returns:
      hash of the bytes written - the manifest fingerprint
      Throws:
      IOException - the manifest can not be written
    • verify

      public static SealVerification verify(File root, File manifestFile, String manifestFingerprint, SealVerificationLevel level)
      Compare sealed content with its manifest.
      Parameters:
      root - the sealed file or directory
      manifestFile - the manifest file
      manifestFingerprint - the hash of the manifest that was recorded when the content was sealed
      level - how thorough to be (QUICK or FULL)
      Returns:
      what was found