org.egothor.duplicity.file
Class MergeableSimilarUnitPairsFile

java.lang.Object
  extended by org.egothor.duplicity.file.DuplicityCheckingFile
      extended by org.egothor.duplicity.file.CommonSimilarUnitPairsFile
          extended by org.egothor.duplicity.file.MergeableSimilarUnitPairsFile
Direct Known Subclasses:
AllSimilarUnitPairsFile, SimilarUnitPairsFile

public abstract class MergeableSimilarUnitPairsFile
extends CommonSimilarUnitPairsFile

Adds abilitity to merge to the CommonSimilarUnitPairsFile class.

Author:
Kate�ina Dufkov�

Nested Class Summary
 
Nested classes/interfaces inherited from class org.egothor.duplicity.file.DuplicityCheckingFile
DuplicityCheckingFile.TempFile
 
Field Summary
protected  int lastLoading
          Helper value for the merge() method.
 
Fields inherited from class org.egothor.duplicity.file.CommonSimilarUnitPairsFile
permID
 
Fields inherited from class org.egothor.duplicity.file.DuplicityCheckingFile
location, out
 
Constructor Summary
protected MergeableSimilarUnitPairsFile()
           
 
Method Summary
protected abstract  void checkPermutation(long permID1, long permID2)
          Checks if files with given permutations can be merged.
protected  void mergeAll(CommonSimilarUnitPairsFile mergeTo, java.util.ArrayList<CommonSimilarUnitPairsFile> supfs)
          Merges multiple files externally, on filesystem.
protected  void mergeAll(DataOutputStream dos, java.util.ArrayList<DataInputStream> diss, java.util.ArrayList<UnitPair> ups)
          Merges all given input streams to given output stream.
protected  void openInputs(java.util.ArrayList<CommonSimilarUnitPairsFile> supfs, java.util.ArrayList<DataInputStream> diss, java.util.ArrayList<UnitPair> ups)
          Open input files in supfs and put the opened non-empty DataInputStreams to given list diss list, and the first elements of the files to ups list.
 
Methods inherited from class org.egothor.duplicity.file.CommonSimilarUnitPairsFile
dump, getPermID, hasTheSameContent, remove, toString
 
Methods inherited from class org.egothor.duplicity.file.DuplicityCheckingFile
createOut, createPermOut, createTempOut, delete, dump, getFilename, getLocation, getNewTempFile, getOut, hasTheSameContent, initFromProducer, openOut, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lastLoading

protected int lastLoading
Helper value for the merge() method. Ordinal number of the stream from which we tried to load in the previous step.

Constructor Detail

MergeableSimilarUnitPairsFile

protected MergeableSimilarUnitPairsFile()
Method Detail

mergeAll

protected void mergeAll(CommonSimilarUnitPairsFile mergeTo,
                        java.util.ArrayList<CommonSimilarUnitPairsFile> supfs)
                 throws java.io.IOException,
                        MergeException
Merges multiple files externally, on filesystem. If the files must correnspond to the same permutation depends on the implementation of checkPermutation(long) method in childs. The method is written so that there is no problem if the output file is also between the input streams, because it uses temporary file and only after it finished merging, renames the result to output file. Warning: The content of the output file mergeTo will be discarded.

Parameters:
mergeTo - file where the result will be placed
supfs - list of files to be merged. Can be regular (SimilarUnitPairsFile or SimilarUnitPairsFile) or temporary (SimilarUnitPairsTempFile).
Throws:
MergeException - on attempt to merge files corresponding to different permutations
java.io.IOException - if temporary file could not be created

mergeAll

protected void mergeAll(DataOutputStream dos,
                        java.util.ArrayList<DataInputStream> diss,
                        java.util.ArrayList<UnitPair> ups)
                 throws java.io.IOException
Merges all given input streams to given output stream. Expects to get the leading element (first element not written to output) of each input stream in variable ups.

Parameters:
dos - DataOutputStream to which to write output
diss - list of DataInputStreams to be merged
ups - leading elements of streams
Throws:
java.io.IOException - on error reading/writing from/to stream

openInputs

protected void openInputs(java.util.ArrayList<CommonSimilarUnitPairsFile> supfs,
                          java.util.ArrayList<DataInputStream> diss,
                          java.util.ArrayList<UnitPair> ups)
                   throws java.io.IOException
Open input files in supfs and put the opened non-empty DataInputStreams to given list diss list, and the first elements of the files to ups list.

Parameters:
supfs - list of files to be opened
diss - output list of opened streams
ups - output list of first elements of the non-empty files
Throws:
java.io.IOException

checkPermutation

protected abstract void checkPermutation(long permID1,
                                         long permID2)
                                  throws MergeException
Checks if files with given permutations can be merged.

Parameters:
permID1 - id of first permutation
permID2 - id of second permutation
Throws:
MergeException - on attempt to merge files corresponding to different permutations