org.metastatic.rsync
Class Rdiff

java.lang.Object
  |
  +--org.metastatic.rsync.Rdiff

public class Rdiff
extends Object

A re-implementation of the rdiff utility from librsync. For more info see the rproxy page.


Field Summary
protected  int blockLength
          The length of blocks to checksum.
static short CHAR_OFFSET
           
static int CHUNK_SIZE
           
static String DELTA
          The `delta' command.
static int DELTA_MAGIC
          Rdiff/rproxy delta magic.
protected static LongOpt[] LONGOPTS
          The long options.
static byte OP_COPY_N4_N4
           
static byte OP_END
           
static byte OP_LITERAL_N1
           
static byte OP_LITERAL_N2
           
static byte OP_LITERAL_N4
           
static byte OP_LITERAL_N8
           
protected static String OPTSTRING
          The short options.
static String PATCH
          The `patch' command.
static String PROGNAME
          The program name printed to the console.
static int RDIFF_BLOCK_LENGTH
          Rdiff/rproxy default block length.
static int RDIFF_STRONG_LENGTH
          Rdiff/rproxy default sum length.
static int SIG_MAGIC
          Rdiff/rproxy signature magic.
static String SIGNATURE
          The `signature' command.
protected  int strongSumLength
          The effective strong signature length.
static int SUM_LENGTH
          The strong checksum length.
protected static boolean verbose
          Whether or not to trace to System.err.
 
Constructor Summary
Rdiff()
          Create an Rdiff object.
 
Method Summary
static void main(String[] argv)
          Main entry point for console use.
 List makeDeltas(List sums, InputStream in)
          Make a collection of Deltas from the given sums and InputStream.
 void makeDeltas(List sums, InputStream in, OutputStream out)
           
 List makeSignatures(InputStream in)
          Make the signatures from data coming in through the input stream.
 void makeSignatures(InputStream in, OutputStream out)
          Generate and write the signatures.
 List readDeltas(InputStream in)
          Read a collection of Deltas from the InputStream.
 List readSignatures(InputStream in)
          Read the signatures from the input stream.
 void rebuildFile(File basis, InputStream deltas, OutputStream out)
           
 void rebuildFile(File basis, List deltas, OutputStream out)
          Patch the file basis using deltas, writing the patched file to out.
 void writeDeltas(List deltas, OutputStream out)
          Write deltas to an output stream.
 void writeSignatures(List sigs, OutputStream out)
          Write the signatures to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTSTRING

protected static final String OPTSTRING
The short options.

See Also:
Constant Field Values

LONGOPTS

protected static final LongOpt[] LONGOPTS
The long options.


SUM_LENGTH

public static final int SUM_LENGTH
The strong checksum length.

See Also:
Constant Field Values

CHUNK_SIZE

public static final int CHUNK_SIZE
See Also:
Constant Field Values

RDIFF_BLOCK_LENGTH

public static final int RDIFF_BLOCK_LENGTH
Rdiff/rproxy default block length.

See Also:
Constant Field Values

RDIFF_STRONG_LENGTH

public static final int RDIFF_STRONG_LENGTH
Rdiff/rproxy default sum length.

See Also:
Constant Field Values

SIG_MAGIC

public static final int SIG_MAGIC
Rdiff/rproxy signature magic.

See Also:
Constant Field Values

DELTA_MAGIC

public static final int DELTA_MAGIC
Rdiff/rproxy delta magic.

See Also:
Constant Field Values

OP_END

public static final byte OP_END
See Also:
Constant Field Values

OP_LITERAL_N1

public static final byte OP_LITERAL_N1
See Also:
Constant Field Values

OP_LITERAL_N2

public static final byte OP_LITERAL_N2
See Also:
Constant Field Values

OP_LITERAL_N4

public static final byte OP_LITERAL_N4
See Also:
Constant Field Values

OP_LITERAL_N8

public static final byte OP_LITERAL_N8
See Also:
Constant Field Values

OP_COPY_N4_N4

public static final byte OP_COPY_N4_N4
See Also:
Constant Field Values

SIGNATURE

public static final String SIGNATURE
The `signature' command.

See Also:
Constant Field Values

DELTA

public static final String DELTA
The `delta' command.

See Also:
Constant Field Values

PATCH

public static final String PATCH
The `patch' command.

See Also:
Constant Field Values

PROGNAME

public static final String PROGNAME
The program name printed to the console.

See Also:
Constant Field Values

CHAR_OFFSET

public static final short CHAR_OFFSET
See Also:
Constant Field Values

verbose

protected static boolean verbose
Whether or not to trace to System.err.


blockLength

protected int blockLength
The length of blocks to checksum.


strongSumLength

protected int strongSumLength
The effective strong signature length.

Constructor Detail

Rdiff

public Rdiff()
Create an Rdiff object.

Method Detail

main

public static void main(String[] argv)
                 throws Throwable
Main entry point for console use.

Parameters:
argv - The argument vector.
Throwable

makeSignatures

public void makeSignatures(InputStream in,
                           OutputStream out)
                    throws IOException,
                           NoSuchAlgorithmException
Generate and write the signatures.

IOException
NoSuchAlgorithmException

writeSignatures

public void writeSignatures(List sigs,
                            OutputStream out)
                     throws IOException
Write the signatures to the specified output stream.

Parameters:
sigs - The signatures to write.
out - The OutputStream to write to.
Throws:
IOException - If writing fails.

makeSignatures

public List makeSignatures(InputStream in)
                    throws IOException,
                           NoSuchAlgorithmException
Make the signatures from data coming in through the input stream.

Parameters:
in - The input stream to generate signatures for.
Returns:
A List of signatures.
Throws:
IOException - If reading fails.
NoSuchAlgorithmException

readSignatures

public List readSignatures(InputStream in)
                    throws IOException
Read the signatures from the input stream.

Parameters:
in - The InputStream to read the signatures from.
Returns:
A collection of ChecksumPairs read.
Throws:
IOException - If the input stream is malformed.

makeDeltas

public void makeDeltas(List sums,
                       InputStream in,
                       OutputStream out)
                throws IOException,
                       NoSuchAlgorithmException
IOException
NoSuchAlgorithmException

writeDeltas

public void writeDeltas(List deltas,
                        OutputStream out)
                 throws IOException
Write deltas to an output stream.

Parameters:
deltas - A collection of Deltas to write.
out - The OutputStream to write to.
Throws:
IOException - If writing fails.

makeDeltas

public List makeDeltas(List sums,
                       InputStream in)
                throws IOException,
                       NoSuchAlgorithmException
Make a collection of Deltas from the given sums and InputStream.

Parameters:
sums - A collection of ChecksumPairs generated from the "old" file.
in - The InputStream for the "new" file.
Returns:
A collection of Deltas that will patch the old file to the new.
Throws:
IOException - If reading fails.
NoSuchAlgorithmException

readDeltas

public List readDeltas(InputStream in)
                throws IOException
Read a collection of Deltas from the InputStream.

Parameters:
in - The InputStream to read from.
Returns:
A collection of Deltas read.
Throws:
IOException - If the input stream is malformed.

rebuildFile

public void rebuildFile(File basis,
                        InputStream deltas,
                        OutputStream out)
                 throws IOException
IOException

rebuildFile

public void rebuildFile(File basis,
                        List deltas,
                        OutputStream out)
                 throws IOException
Patch the file basis using deltas, writing the patched file to out.

Parameters:
basis - The basis file.
deltas - The collection of Deltas to apply.
out - The OutputStream to write the patched file to.
Throws:
IOException - If reading/writing fails.