com.nothome.delta
Class Delta

java.lang.Object
  extended by com.nothome.delta.Delta

public class Delta
extends Object

Class for computing deltas against a source. The source file is read by blocks and a hash is computed per block. Then the target is scanned for matching blocks.

This class is not thread safe. Use one instance per thread.

This class should support files over 4GB in length, although you must use a larger checksum size, such as 1K, as all checksums use "int" indexing. Newer versions may eventually support paging in/out of checksums.


Field Summary
static int DEFAULT_CHUNK_SIZE
          Default size of 16.
 
Constructor Summary
Delta()
          Constructs a new Delta.
 
Method Summary
 byte[] compute(byte[] source, byte[] target)
          Compares the source bytes with target bytes, returning output.
 void compute(byte[] source, byte[] target, OutputStream output)
          Compares the source bytes with target bytes, writing to output.
 void compute(byte[] sourceBytes, InputStream inputStream, DiffWriter diffWriter)
          Compares the source bytes with target input, writing to output.
 void compute(File sourceFile, File targetFile, DiffWriter output)
          Compares the source file with a target file, writing to output.
 void compute(SeekableSource seekSource, InputStream targetIS, DiffWriter output)
          Compares the source with a target, writing to output.
static void main(String[] argv)
          Creates a patch using file names.
 void setChunkSize(int size)
          Sets the chunk size used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHUNK_SIZE

public static final int DEFAULT_CHUNK_SIZE
Default size of 16. For "Lorem ipsum" text files (see the tests) the ideal size is about 14. Any smaller and the patch size becomes actually be larger.

Use a size like 64 or 128 for large files.

See Also:
Constant Field Values
Constructor Detail

Delta

public Delta()
Constructs a new Delta. In the future, additional constructor arguments will set the algorithm details.

Method Detail

setChunkSize

public void setChunkSize(int size)
Sets the chunk size used. Larger chunks are faster and use less memory, but create larger patches as well.

Parameters:
size -

compute

public void compute(byte[] source,
                    byte[] target,
                    OutputStream output)
             throws IOException
Compares the source bytes with target bytes, writing to output.

Throws:
IOException

compute

public byte[] compute(byte[] source,
                      byte[] target)
               throws IOException
Compares the source bytes with target bytes, returning output.

Throws:
IOException

compute

public void compute(byte[] sourceBytes,
                    InputStream inputStream,
                    DiffWriter diffWriter)
             throws IOException
Compares the source bytes with target input, writing to output.

Throws:
IOException

compute

public void compute(File sourceFile,
                    File targetFile,
                    DiffWriter output)
             throws IOException
Compares the source file with a target file, writing to output.

Parameters:
output - will be closed
Throws:
IOException

compute

public void compute(SeekableSource seekSource,
                    InputStream targetIS,
                    DiffWriter output)
             throws IOException
Compares the source with a target, writing to output.

Parameters:
output - will be closed
Throws:
IOException

main

public static void main(String[] argv)
                 throws Exception
Creates a patch using file names.

Throws:
Exception


Copyright © 2003-2008. All Rights Reserved.