dk.netarkivet.archive.checksum
Class ChecksumArchive

java.lang.Object
  extended by dk.netarkivet.archive.checksum.ChecksumArchive
Direct Known Subclasses:
FileChecksumArchive

public abstract class ChecksumArchive
extends java.lang.Object

This abstract class is the interface for the checksum archives, which can be one of the following:
- FileChecksumArchive where the archive is placed in a single file.
TODO
- DatabaseChecksumArchive where the archive is placed in a database.

See Also:
FileChecksumArchive

Constructor Summary
protected ChecksumArchive()
          Constructor.
 
Method Summary
protected abstract  java.lang.String calculateChecksum(java.io.File f)
          Method for calculating the checksum of a specific file.
protected abstract  java.lang.String calculateChecksum(java.io.InputStream is)
          Method for calculating the checksum when the file is received in the form of an inputstream.
abstract  void cleanup()
          Method for cleaning up when closing down.
abstract  java.io.File correct(java.lang.String filename, java.io.File correctFile)
          Method for removing a bad entry from the archive.
abstract  java.io.File getAllFilenames()
          Method for retrieving the names of all the files within the archive as a temporary file.
abstract  java.io.File getArchiveAsFile()
          Method for retrieving the archive as a temporary file containing the checksum entries.
abstract  java.lang.String getChecksum(java.lang.String filename)
          Method for retrieving the checksum of a specific entry in the archive.
abstract  boolean hasEnoughSpace()
          Method for checking whether there is enough space left on the hard drive.
abstract  boolean hasEntry(java.lang.String filename)
          Method for checking whether an entry exists within the archive.
abstract  void upload(RemoteFile arcfile, java.lang.String filename)
          Method for uploading a new file to the archive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChecksumArchive

protected ChecksumArchive()
Constructor.

Method Detail

hasEnoughSpace

public abstract boolean hasEnoughSpace()
Method for checking whether there is enough space left on the hard drive.

Returns:
Whether there is enough space left on the hard drive.

correct

public abstract java.io.File correct(java.lang.String filename,
                                     java.io.File correctFile)
                              throws IOFailure,
                                     ArgumentNotValid,
                                     IllegalState
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.

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:
ArgumentNotValid - If one of the arguments are not valid.
IOFailure - If the entry cannot be corrected.
IllegalState - If no such entry exists to be corrected, or if the entry has a different checksum than expected.

getChecksum

public abstract java.lang.String getChecksum(java.lang.String filename)
Method for retrieving the checksum of a specific entry in the archive.

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 abstract boolean hasEntry(java.lang.String filename)
Method for checking whether an entry exists within the archive.

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 abstract void upload(RemoteFile arcfile,
                            java.lang.String filename)
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.

Parameters:
arcfile - The remote file to be uploaded.
filename - The name of the file.

calculateChecksum

protected abstract java.lang.String calculateChecksum(java.io.File f)
Method for calculating the checksum of a specific file.

Parameters:
f - The file to calculate the checksum from.
Returns:
The checksum of the file.

calculateChecksum

protected abstract java.lang.String calculateChecksum(java.io.InputStream is)
Method for calculating the checksum when the file is received in the form of an inputstream.

Parameters:
is - The input stream to calculate the checksum from.
Returns:
The checksum of the inputstream.

getArchiveAsFile

public abstract java.io.File getArchiveAsFile()
Method for retrieving the archive as a temporary file containing the checksum entries.

Returns:
A temporary checksum file.

getAllFilenames

public abstract java.io.File getAllFilenames()
Method for retrieving the names of all the files within the archive as a temporary file.

Returns:
A temporary file containing the list of all the filenames. This file has one filename per line.

cleanup

public abstract void cleanup()
Method for cleaning up when closing down.