Class BitarchiveAdmin


  • public final class BitarchiveAdmin
    extends java.lang.Object
    This class handles file lookup and encapsulates the actual placement of files.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close down the bitarchive admin.
      java.io.File getAtticPath​(java.io.File existingFile)
      Return the path used to store files that are removed by RemoveAndGetFileMessage.
      java.io.File[] getFiles()
      Return array with references to all files in the archive.
      java.io.File[] getFilesMatching​(java.util.regex.Pattern regexp)
      Return an array of all files in this archive that match a given regular expression on the filename.
      static BitarchiveAdmin getInstance()
      Get the one and only instance of the bitarchive admin.
      java.io.File getTemporaryPath​(java.lang.String arcFileName, long requestedSize)
      Returns a temporary place for the the file to be stored.
      boolean hasEnoughSpace()
      Returns true if we have at least one dir with the required amount of space left.
      protected boolean isBitarchiveDirectory​(java.io.File theDir)
      Checks whether a directory is one of the known bitarchive directories.
      boolean isReadonlyMode()  
      BitarchiveARCFile lookup​(java.lang.String arcFileName)
      Return the path that a given arc file can be found in.
      java.io.File moveToStorage​(java.io.File tempLocation)
      Moves a file from temporary storage to file storage.
      void updateFileList​(java.io.File basedir)
      Method for updating the filelist for a given basedir.
      void verifyFilelistUpToDate()
      Checks whether the filelist is up to date.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • verifyFilelistUpToDate

        public void verifyFilelistUpToDate()
        Checks whether the filelist is up to date. If the modified timestamp for the a directory is larger than the last recorded timestamp, then the stored filelist is updated with the latest changes.
      • updateFileList

        public void updateFileList​(java.io.File basedir)
                            throws ArgumentNotValid,
                                   UnknownID,
                                   IOFailure
        Method for updating the filelist for a given basedir.
        Parameters:
        basedir - The basedir to update the filelist for.
        Throws:
        ArgumentNotValid - If basedir is null or if it not a proper directory.
        UnknownID - If the basedir cannot be found both the archivedFiles map or the archiveTime map, or if the file-directory under basedir is not either a writable directory or a symbolic link
        IOFailure - If it is not possible to retrieve the canonical file for the basedir.
      • hasEnoughSpace

        public boolean hasEnoughSpace()
        Returns true if we have at least one dir with the required amount of space left.
        Returns:
        true if we have at least one dir with the required amount of space left, otherwise false.
      • getTemporaryPath

        public java.io.File getTemporaryPath​(java.lang.String arcFileName,
                                             long requestedSize)
                                      throws ArgumentNotValid,
                                             IOFailure
        Returns a temporary place for the the file to be stored.
        Parameters:
        arcFileName - The simple name (i.e. no dirs) of the ARC file.
        requestedSize - How large the file is in bytes.
        Returns:
        The path where the arcFile should go.
        Throws:
        ArgumentNotValid - If arcFileName is null or empty, or requestedSize is negative.
        IOFailure - if there is no more room left to store this file of size=requestedSize
      • moveToStorage

        public java.io.File moveToStorage​(java.io.File tempLocation)
                                   throws IOFailure,
                                          ArgumentNotValid
        Moves a file from temporary storage to file storage.

        Note: It is checked, if tempLocation resides in directory TEMPORARY_DIRECTORY_NAME and whether the parent of tempLocation is a Bitarchive directory.

        Parameters:
        tempLocation - The temporary location where the file was stored. This must be a path returned from getTemporaryPath
        Returns:
        The location where the file is now stored
        Throws:
        IOFailure - if tempLocation is not created from getTemporaryPath or file cannot be moved to Storage location.
        ArgumentNotValid - If the tempLocation file is null.
      • isBitarchiveDirectory

        protected boolean isBitarchiveDirectory​(java.io.File theDir)
                                         throws ArgumentNotValid,
                                                IOFailure
        Checks whether a directory is one of the known bitarchive directories.
        Parameters:
        theDir - The dir to check
        Returns:
        true If it is a valid archive directory; otherwise returns false.
        Throws:
        IOFailure - if theDir or one of the valid archive directories does not exist
        ArgumentNotValid - if theDir is null
      • getFiles

        public java.io.File[] getFiles()
        Return array with references to all files in the archive.
        Returns:
        array with references to all files in the archive
      • getFilesMatching

        public java.io.File[] getFilesMatching​(java.util.regex.Pattern regexp)
        Return an array of all files in this archive that match a given regular expression on the filename.
        Parameters:
        regexp - A precompiled regular expression matching whole filenames. This will probably be given to a FilenameFilter
        Returns:
        An array of all the files in this bitarchive that exactly match the regular expression on the filename (sans paths).
      • lookup

        public BitarchiveARCFile lookup​(java.lang.String arcFileName)
        Return the path that a given arc file can be found in.
        Parameters:
        arcFileName - Name of an arc file (with no path)
        Returns:
        A BitarchiveARCFile for the given file, or null if the file does not exist.
      • getInstance

        public static BitarchiveAdmin getInstance()
        Get the one and only instance of the bitarchive admin.
        Returns:
        A BitarchiveAdmin object
      • close

        public void close()
        Close down the bitarchive admin. Currently has no data to store.
      • getAtticPath

        public java.io.File getAtticPath​(java.io.File existingFile)
        Return the path used to store files that are removed by RemoveAndGetFileMessage.
        Parameters:
        existingFile - a File object for an existing file in the bitarchive
        Returns:
        The full path of the file in the attic dir