org.metastatic.rsync
Class Generator

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

public class Generator
extends Object

Checksum generation methods.


Field Summary
protected  Configuration config
          Our configuration.
 
Constructor Summary
Generator(Configuration config)
           
 
Method Summary
 ChecksumPair generateSum(byte[] buf, int off, int len, long fileOffset)
          Generate a sum pair for a portion of a byte array.
 ChecksumPair generateSum(byte[] buf, long fileOffset)
          Generate a sum pair for an entire byte array.
 List generateSums(byte[] buf)
          Generate checksums over an entire byte array, with a base offset of 0.
 List generateSums(byte[] buf, int off, int len)
          Generate checksums over a portion of a byte array, with a base offset of 0.
 List generateSums(byte[] buf, int off, int len, long baseOffset)
          Generate checksums over a portion of abyte array, with a specified base offset.
 List generateSums(byte[] buf, long baseOffset)
          Generate checksums over an entire byte array, with a specified base offset.
 List generateSums(File f)
          Generate checksums for an entire file.
 List generateSums(InputStream in)
          Generate checksums for an InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

protected final Configuration config
Our configuration. Contains such things as our rolling checksum and message digest.

Constructor Detail

Generator

public Generator(Configuration config)
Method Detail

generateSums

public List generateSums(byte[] buf)
Generate checksums over an entire byte array, with a base offset of 0.

Parameters:
buf - The byte buffer to checksum.
Returns:
A List of ChecksumPairs generated from the array.
See Also:
generateSums(byte[],int,int,long)

generateSums

public List generateSums(byte[] buf,
                         int off,
                         int len)
Generate checksums over a portion of a byte array, with a base offset of 0.

Parameters:
buf - The byte array to checksum.
off - The offset in buf to begin.
len - The number of bytes to checksum.
Returns:
A List of ChecksumPairs generated from the array.
See Also:
generateSums(byte[],int,int,long)

generateSums

public List generateSums(byte[] buf,
                         long baseOffset)
Generate checksums over an entire byte array, with a specified base offset. This baseOffset is added to the offset stored in each ChecksumPair.

Parameters:
buf - The byte array to checksum.
baseOffset - The offset from whence this byte array came.
Returns:
A List of ChecksumPairs generated from the array.
See Also:
generateSums(byte[],int,int,long)

generateSums

public List generateSums(byte[] buf,
                         int off,
                         int len,
                         long baseOffset)
Generate checksums over a portion of abyte array, with a specified base offset. This baseOffset is added to the offset stored in each ChecksumPair.

Parameters:
buf - The byte array to checksum.
off - From whence in buf to start.
len - The number of bytes to check in buf.
baseOffset - The offset from whence this byte array came.
Returns:
A List of ChecksumPairs generated from the array.

generateSums

public List generateSums(File f)
                  throws IOException
Generate checksums for an entire file.

Parameters:
f - The File to checksum.
Returns:
A List of ChecksumPairs generated from the file.
Throws:
IOException - if f cannot be read from.

generateSums

public List generateSums(InputStream in)
                  throws IOException
Generate checksums for an InputStream.

Parameters:
in - The InputStream to checksum.
Returns:
A List of ChecksumPairs generated from the bytes read.
Throws:
IOException - if reading fails.

generateSum

public ChecksumPair generateSum(byte[] buf,
                                long fileOffset)
Generate a sum pair for an entire byte array.

Parameters:
buf - The byte array to checksum.
fileOffset - The offset in the original file from whence this block came.
Returns:
A ChecksumPair for this byte array.

generateSum

public ChecksumPair generateSum(byte[] buf,
                                int off,
                                int len,
                                long fileOffset)
Generate a sum pair for a portion of a byte array.

Parameters:
buf - The byte array to checksum.
off - Where in buf to start.
len - How many bytes to checksum.
fileOffset - The original offset of this byte array.
Returns:
A ChecksumPair for this byte array.