Class DatabaseChecksumArchive

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String calculateChecksum​(java.io.File f)
      Method for calculating the checksum of a specific file.
      java.lang.String calculateChecksum​(java.io.InputStream is)
      Method for calculating the checksum when the file is received in the form of an inputstream.
      void cleanup()
      Method for cleaning up when closing down.
      java.io.File correct​(java.lang.String filename, java.io.File correctFile)
      Method for removing a bad entry from the archive.
      java.io.File getAllFilenames()
      Method for retrieving the names of all the files within the archive as a temporary file.
      java.io.File getArchiveAsFile()
      Method for retrieving the archive as a temporary file containing the checksum entries.
      java.lang.String getChecksum​(java.lang.String filename)
      Method for retrieving the checksum of a specific entry in the archive.
      static DatabaseChecksumArchive getInstance()
      Method for obtaining the current singleton instance of this class.
      boolean hasEnoughSpace()
      Method for checking whether there is enough space left on the hard drive.
      boolean hasEntry​(java.lang.String filename)
      Method for checking whether an entry exists within the archive.
      void put​(java.lang.String filename, java.lang.String checksum)
      Update the database with a new filename and its checksum.
      void upload​(RemoteFile file, java.lang.String filename)
      Method for uploading a new file to the archive.
      void upload​(java.lang.String checksum, java.lang.String filename)
      Upload a filename with a pre-computed checksum.
      • Methods inherited from class java.lang.Object

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

      • DatabaseChecksumArchive

        public DatabaseChecksumArchive()
                                throws com.sleepycat.je.DatabaseException
        Constructor. Retrieves the minimum space left variable, and ensures the existence of the archive file. If the file does not exist, then it is created.
        Throws:
        java.lang.Exception
        com.sleepycat.je.DatabaseException
    • Method Detail

      • getInstance

        public static DatabaseChecksumArchive getInstance()
                                                   throws java.lang.Exception
        Method for obtaining the current singleton instance of this class. If the instance of this class has not yet been constructed, then it will be initialised.
        Returns:
        The current instance of this class.
        Throws:
        java.lang.Exception
      • hasEnoughSpace

        public boolean hasEnoughSpace()
        Description copied from interface: ChecksumArchive
        Method for checking whether there is enough space left on the hard drive.
        Specified by:
        hasEnoughSpace in interface ChecksumArchive
        Returns:
        Whether there is enough space left on the hard drive.
      • correct

        public java.io.File correct​(java.lang.String filename,
                                    java.io.File correctFile)
                             throws IOFailure,
                                    ArgumentNotValid,
                                    IllegalState
        Description copied from interface: ChecksumArchive
        Method for removing a bad entry from the archive. This finds the record and removes it if it has the incorrect checksum. The incorrect record is not deleted, but instead put into a backup file for all the incorrect records.
        Specified by:
        correct in interface ChecksumArchive
        Parameters:
        filename - The name of the file whose record should be removed.
        correctFile - The correct remote file to replace the bad one in the archive.
        Returns:
        A file containing the removed data.
        Throws:
        IOFailure - If the entry cannot be corrected.
        ArgumentNotValid - If one of the arguments are not valid.
        IllegalState - If no such entry exists to be corrected, or if the entry has a different checksum than expected.
      • getChecksum

        public java.lang.String getChecksum​(java.lang.String filename)
        Description copied from interface: ChecksumArchive
        Method for retrieving the checksum of a specific entry in the archive.
        Specified by:
        getChecksum in interface ChecksumArchive
        Parameters:
        filename - The name of the file entry in the archive for whom the checksum should be retrieved.
        Returns:
        The checksum of a record, or null if it was not found.
      • hasEntry

        public boolean hasEntry​(java.lang.String filename)
        Description copied from interface: ChecksumArchive
        Method for checking whether an entry exists within the archive.
        Specified by:
        hasEntry in interface ChecksumArchive
        Parameters:
        filename - The name of the file whose entry in the archive should be determined.
        Returns:
        Whether an entry with the filename was found.
      • upload

        public void upload​(RemoteFile file,
                           java.lang.String filename)
        Description copied from interface: ChecksumArchive
        Method for uploading a new file to the archive. The checksum of the file needs to be calculated before it is placed in the archive with the given filename.
        Specified by:
        upload in interface ChecksumArchive
        Parameters:
        file - The remote file to be uploaded.
        filename - The name of the file.
      • upload

        public void upload​(java.lang.String checksum,
                           java.lang.String filename)
        Description copied from interface: ChecksumArchive
        Upload a filename with a pre-computed checksum.
        Specified by:
        upload in interface ChecksumArchive
      • put

        public void put​(java.lang.String filename,
                        java.lang.String checksum)
        Update the database with a new filename and its checksum.
        Parameters:
        filename - A given filename
        checksum - The related checksum
      • calculateChecksum

        public java.lang.String calculateChecksum​(java.io.File f)
        Description copied from interface: ChecksumArchive
        Method for calculating the checksum of a specific file.
        Specified by:
        calculateChecksum in interface ChecksumArchive
        Parameters:
        f - The file to calculate the checksum from.
        Returns:
        The checksum of the file.
      • calculateChecksum

        public java.lang.String calculateChecksum​(java.io.InputStream is)
        Description copied from interface: ChecksumArchive
        Method for calculating the checksum when the file is received in the form of an inputstream.
        Specified by:
        calculateChecksum in interface ChecksumArchive
        Parameters:
        is - The input stream to calculate the checksum from.
        Returns:
        The checksum of the inputstream.
      • getAllFilenames

        public java.io.File getAllFilenames()
        Description copied from interface: ChecksumArchive
        Method for retrieving the names of all the files within the archive as a temporary file.
        Specified by:
        getAllFilenames in interface ChecksumArchive
        Returns:
        A temporary file containing the list of all the filenames. This file has one filename per line.