Class BagItAipReader


  • public class BagItAipReader
    extends Object
    Assist in reading aips and retrieving information from the package.
    Since:
    2020-03-19
    Author:
    mikejritter
    • Constructor Detail

      • BagItAipReader

        public BagItAipReader​(Path bag)
                       throws IOException
        Constructor for a BagItAipReader. If the given path to the bag is a single file, it is assumed that the path is an archived aip and will be deserialized.
        Parameters:
        bag - the Path to the bag
        Throws:
        IOException - if there are any errors while deserializing the aip located at Path
    • Method Detail

      • validateBag

        public void validateBag()
        Validate that an AIP is in a BagIt format which passes both bagit-bag validation and bagit-profile validation
        Throws:
        RuntimeException - if there is an error during validation
      • readProperties

        public Properties readProperties()
                                  throws IOException
        Retrieve the object.properties for an aip
        Returns:
        the Properties, loaded from the data/object.properties
        Throws:
        IOException - if there is an error loading the properties
      • readFile

        public List<String> readFile​(String relativePath)
        Read a file's lines given a relative path to the file. If a file does not exist, or an error is encountered while trying to read the file an empty list is returned. Note: the path given should be in relation to the data directory, not the root of the bag
        Parameters:
        relativePath - the relative path of the file to retrieve
        Returns:
        the lines of the files, as a List of Strings. If the file does not exist, an empty list will be returned so this method should not be used
      • findLogo

        public com.google.common.base.Optional<Path> findLogo()
                                                       throws IOException
        Retrieve the logo for an aip, if it is available
        Returns:
        an Optional containing the InputStream of the logo if it exists, and Optional.absent() otherwise
        Throws:
        IOException - if there is an error getting the InputStream for the logo
      • readMetadata

        public Metadata readMetadata()
                              throws IOException
        Read the metadata.xml file located in a bags data directory
        Returns:
        the Metadata with values read from data/metadata.xml
        Throws:
        IOException - if there was an error reading the file or parsing the xml
      • findItemTemplate

        public com.google.common.base.Optional<Metadata> findItemTemplate()
                                                                   throws IOException
        Search for Metadata for an Item Template in a Bag
        Returns:
        the Metadata with values read from data/template-metadata.xml if it exists
        Throws:
        IOException
      • readPolicy

        public Policies readPolicy()
                            throws IOException
        Read the policy.xml file located in a bags data directory
        Returns:
        the Policy with values read from data/policy.xml
        Throws:
        IOException - if there was an error reading the file or parsing the xml
      • findRoles

        public com.google.common.base.Optional<Path> findRoles()
        Attempt to find the data/roles.xml within a Bag. If it does not exist, return an empty Optional.
        Returns:
        an Optional containing the Path for the roles.xml, if it exists
      • clean

        public void clean()
                   throws IOException
        Finish operations and remove the aip
        Throws:
        IOException - if there are any errors removing the aip