org.metastatic.rsync
Class RebuilderStream

java.lang.Object
  |
  +--org.metastatic.rsync.RebuilderStream
Direct Known Subclasses:
MappedRebuilderStream

public class RebuilderStream
extends Object

A "streaming" alternative to Rebuilder. To use this class, create an intsance with a file argument representing the file being rebuilt. Then register one or more implementations of the RebuilderListener interface, which will write the data to the new file. Then call the update(Delta) method for each Delta to be applied.

Note that unlike the GeneratorStream and MatcherStream classes this class does not need a Configuration, nor does it have any "doFinal" method -- it is completely stateless (except for the file) and the operations are finished when the last delta has been applied.

This class is optimal for situations where the deltas are coming in a stream over a communications link, and when it would be inefficient to wait until all deltas are received.


Field Summary
protected  RandomAccessFile basisFile
          The basis file.
protected  LinkedList listeners
          The list of RebuilderListeners.
 
Constructor Summary
RebuilderStream()
          Create a new rebuilder.
 
Method Summary
 void addListener(RebuilderListener listener)
          Add a RebuilderListener listener to this rebuilder.
 void doFinal()
           
 void removeListener(RebuilderListener listener)
          Remove a listener from this rebuilder.
 void setBasisFile(File file)
          Set the basis file.
 void setBasisFile(String file)
          Set the basis file.
 void update(Delta delta)
          Update this rebuilder with a delta.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

basisFile

protected RandomAccessFile basisFile
The basis file.


listeners

protected final LinkedList listeners
The list of RebuilderListeners.

Constructor Detail

RebuilderStream

public RebuilderStream()
Create a new rebuilder.

Method Detail

addListener

public void addListener(RebuilderListener listener)
Add a RebuilderListener listener to this rebuilder.

Parameters:
listener - The listener to add.
Throws:
IllegalArgumentException - If listener is null.

removeListener

public void removeListener(RebuilderListener listener)
Remove a listener from this rebuilder.

Parameters:
listener - The listener to remove.

setBasisFile

public void setBasisFile(File file)
                  throws IOException
Set the basis file.

Parameters:
file - The basis file.
Throws:
IOException - If the file is not readable.

setBasisFile

public void setBasisFile(String file)
                  throws IOException
Set the basis file.

Parameters:
file - The basis file name.
Throws:
IOException - If the file name is not the name of a readable file.

doFinal

public void doFinal()
             throws IOException
IOException

update

public void update(Delta delta)
            throws IOException,
                   ListenerException
Update this rebuilder with a delta.

Parameters:
delta - The delta to apply.
Throws:
IOException - If there is an error reading from the basis file, or if no basis file has been specified.
ListenerException