Class BitarchiveAdmin


  • public final class BitarchiveAdmin
    extends Object
    This class handles file lookup and encapsulates the actual placement of files.
    • 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​(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 File getTemporaryPath​(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 File moveToStorage​(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​(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 File[] getFiles()
        Return array with references to all files in the archive.
        Returns:
        array with references to all files in the archive
      • getFilesMatching

        public File[] getFilesMatching​(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​(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 File getAtticPath​(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
      • isReadonlyMode

        public boolean isReadonlyMode()