org.metastatic.rsync
Class DeltaEncoder

java.lang.Object
  |
  +--org.metastatic.rsync.DeltaEncoder
Direct Known Subclasses:
PlainDeltaEncoder

public abstract class DeltaEncoder
extends Object

The superclass of objects that encode sets of deltas to external representations, such as the over-the-wire format of rsync or the rdiff file format.

Subclasses MAY define themselves to be accessable through the #getInstance(java.lang.String,java.io.OutputStream) method by providing a one-argument constructor that accepts an OutputStream and defining the system property "jarsync.deltaEncoder.encoding-name".


Field Summary
protected  Configuration config
          The configuration.
protected  OutputStream out
          The output stream.
static String PROPERTY
           
 
Constructor Summary
DeltaEncoder(Configuration config, OutputStream out)
          Creates a new delta encoder.
 
Method Summary
abstract  void doFinal()
          Finish encoding the deltas (at least, this set of deltas) and write any encoding-specific end-of-deltas entity.
static DeltaEncoder getInstance(String encoding, Configuration config, OutputStream out)
          Returns a new instance of the specified encoder.
abstract  boolean requiresOrder()
          Returns whether or not this encoder requires the deltas it is presented to be in write offset order, that is, the deltas passed to the write methods must be presented in increasing order of their Delta.getWriteOffset() values.
abstract  void write(Delta d)
          Write (encode) a single delta to the output stream.
 void write(List deltas)
          Write (encode) a list of deltas to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY

public static final String PROPERTY
See Also:
Constant Field Values

config

protected Configuration config
The configuration.


out

protected OutputStream out
The output stream.

Constructor Detail

DeltaEncoder

public DeltaEncoder(Configuration config,
                    OutputStream out)
Creates a new delta encoder.

Parameters:
config - The configuration.
out - The output stream to write the data to.
Method Detail

getInstance

public static final DeltaEncoder getInstance(String encoding,
                                             Configuration config,
                                             OutputStream out)
Returns a new instance of the specified encoder.

Throws:
IllegalArgumentException - If there is no appropriate encoder available.

write

public void write(List deltas)
           throws IOException
Write (encode) a list of deltas to the output stream. This method does not call doFinal().

This method checks every element of the supplied list to ensure that all are either non-null or implement the Delta interface, before writing any data.

Parameters:
deltas - The list of deltas to write.
Throws:
IOException - If an I/O error occurs.
IllegalArgumentException - If any element of the list is not a Delta.
NullPointerException - If any element is null.

write

public abstract void write(Delta d)
                    throws IOException
Write (encode) a single delta to the output stream.

Parameters:
d - The delta to write.
Throws:
IOException - If an I/O error occurs.

doFinal

public abstract void doFinal()
                      throws IOException
Finish encoding the deltas (at least, this set of deltas) and write any encoding-specific end-of-deltas entity.

Throws:
IOException - If an I/O error occurs.

requiresOrder

public abstract boolean requiresOrder()
Returns whether or not this encoder requires the deltas it is presented to be in write offset order, that is, the deltas passed to the write methods must be presented in increasing order of their Delta.getWriteOffset() values.

Returns:
True if this encoder requires write order.