org.egothor.duplicity.file
Class DuplicityCheckingFile

java.lang.Object
  extended by org.egothor.duplicity.file.DuplicityCheckingFile
Direct Known Subclasses:
CommonSimilarUnitPairsFile, JaccardCoeficientsFile, PermutatedMinsFile

public abstract class DuplicityCheckingFile
extends java.lang.Object

Ancestor for all the files in org.egothor.duplicity.file package. Provides common data fields with the getters, methods for obtaining String representation, deleting file on filesystem and helper functions for creating temporary and permanent files.

Author:
Kate�ina Dufkov�

Nested Class Summary
protected  class DuplicityCheckingFile.TempFile
           
 
Field Summary
protected  java.lang.String location
          Location of the filesystem file.
protected  File out
          The filesystem file corresponding to this file.
 
Constructor Summary
protected DuplicityCheckingFile()
           
 
Method Summary
protected abstract  void createOut()
          Sets the out field of the class.
protected  void createPermOut()
          The implementation of the createOut() method for permanent files.
protected  void createTempOut()
          The implementation of the createOut() for temporary files.
 void delete()
          Deletes the file from filesystem.
protected  java.lang.String dump(DuplicityCheckingFileElement element)
          Dumps the file with its content to String.
abstract  java.lang.String getFilename()
          Returns the filename corresponding to this file.
 java.lang.String getLocation()
           
protected  DuplicityCheckingFile.TempFile getNewTempFile(java.lang.String filename, java.lang.String existsMessage)
           
 File getOut()
           
 boolean hasTheSameContent(DuplicityCheckingFile file, DuplicityCheckingFileElement element1, DuplicityCheckingFileElement element2)
          Checks if two files has the same content.
protected  void initFromProducer(java.lang.String location, java.util.List<? extends DuplicityCheckingFileElement> buffer)
          Initialializes the file by writing buffer content to disk.
protected  void openOut()
          Opens the file on filesystem and sets the out field.
protected  void remove(DuplicityCheckingFileElement element, java.util.Set<DocumentUnitID> toRemove)
          Removes all occurences of documents given in the set from the file.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

out

protected File out
The filesystem file corresponding to this file.


location

protected java.lang.String location
Location of the filesystem file. This is allways the base directory of the duplicity checking algorithm, never the temp directory inside it.

Constructor Detail

DuplicityCheckingFile

protected DuplicityCheckingFile()
Method Detail

getLocation

public java.lang.String getLocation()

getOut

public File getOut()

delete

public void delete()
Deletes the file from filesystem.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createOut

protected abstract void createOut()
                           throws java.io.IOException
Sets the out field of the class. This may create or open a temporary or permanent file, depending on the implementation in child classes. The location and permID (if present) fields MUST be already set.

Throws:
java.io.IOException

getFilename

public abstract java.lang.String getFilename()
Returns the filename corresponding to this file. The location and permID (if present) fields MUST be already set.


createTempOut

protected void createTempOut()
                      throws java.io.IOException
The implementation of the createOut() for temporary files. The location and permID (if present) fields MUST be already set. Initializes the out field and creates the file on filesystem. The filename is created in temp directory under the directory given in location field and is in form returned by getFilename(). The temp directory must exist. If the file exists, it will be rewritten.

Throws:
java.io.IOException - if the file could not be created

createPermOut

protected void createPermOut()
                      throws java.io.IOException
The implementation of the createOut() method for permanent files. The location and permID (if present) fields MUST be already set. Initializes the out field and creates the file on filesystem. The filename is created in directory given in location field and is in form returned by getFilename(). The directory must exist, the file must NOT exist.

Throws:
java.io.IOException - if the file already exists or could not be created

openOut

protected void openOut()
                throws java.io.FileNotFoundException
Opens the file on filesystem and sets the out field. The location and permID (if present) fields MUST be already set.

Throws:
java.io.FileNotFoundException

dump

protected java.lang.String dump(DuplicityCheckingFileElement element)
Dumps the file with its content to String.

Parameters:
element - instance of the class from which the file consists
Returns:
String representation of the file with its content

getNewTempFile

protected DuplicityCheckingFile.TempFile getNewTempFile(java.lang.String filename,
                                                        java.lang.String existsMessage)
                                                 throws java.io.IOException
Throws:
java.io.IOException

initFromProducer

protected void initFromProducer(java.lang.String location,
                                java.util.List<? extends DuplicityCheckingFileElement> buffer)
                         throws java.io.IOException
Initialializes the file by writing buffer content to disk. The permID field (if present) MUST be already set. Sets location field, creates a file on filesystem for this file and fills it with data from producer object. The filename is in form returned by getFilename() and will be created in the location directory. The directory must exist. If the existence of the file causes an exception depends on the createOut() method provided in the child class.

Parameters:
location - path and name of the directory in which the file will be created, must end with "/" sign
buffer - buffer of elements to be written to the file
Throws:
java.io.IOException - if the file could not be created, or writing data to the file failed

remove

protected void remove(DuplicityCheckingFileElement element,
                      java.util.Set<DocumentUnitID> toRemove)
               throws java.io.IOException
Removes all occurences of documents given in the set from the file.

Parameters:
element - instance of the class from which the file consists
toRemove - set of document ids to remove
Throws:
java.io.IOException

hasTheSameContent

public boolean hasTheSameContent(DuplicityCheckingFile file,
                                 DuplicityCheckingFileElement element1,
                                 DuplicityCheckingFileElement element2)
Checks if two files has the same content.

Parameters:
file - the second file to be tested
element1 - instance of the class from which the file consists
element2 - instance of the class from which the file consists
Returns:
true, if the file contents are the same