org.metastatic.rsync
Class DataBlock

java.lang.Object
  |
  +--org.metastatic.rsync.DataBlock
All Implemented Interfaces:
Delta, Serializable

public class DataBlock
extends Object
implements Delta, Serializable

This is the Delta in the rsync algorithm that introduces new data. It is an array of bytes and an offset, such that the updated file should contain this block at the given offset.

See Also:
Serialized Form

Field Summary
protected  byte[] data
          The block of data to insert.
protected  long offset
          The offset in the file to start this block.
 
Constructor Summary
DataBlock(long offset, byte[] data)
          Create a new instance of a DataBlock with a given offset and block of bytes.
DataBlock(long offset, byte[] data, int off, int len)
          Create a new instance of a DataBlock with a given offset and a portion of a byte array.
 
Method Summary
 boolean equals(Object o)
          Test if another object equals this one.
 int getBlockLength()
          The size of the block of data this class represents.
 byte[] getData()
          Return the array of bytes that is the data block.
 long getOffset()
          Get the offset at which this block should begin.
 long getWriteOffset()
          Get the offset at which this Delta should be written.
 int hashCode()
          Return the hash code for this data block.
 String toString()
          Return a printable string that represents this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected final byte[] data
The block of data to insert.

Since:
1.1

offset

protected final long offset
The offset in the file to start this block.

Since:
1.1
Constructor Detail

DataBlock

public DataBlock(long offset,
                 byte[] data)
Create a new instance of a DataBlock with a given offset and block of bytes.

Parameters:
offset - The offset where this data should go.
data - The data itself.
Since:
1.1

DataBlock

public DataBlock(long offset,
                 byte[] data,
                 int off,
                 int len)
Create a new instance of a DataBlock with a given offset and a portion of a byte array.

Parameters:
offset - The write offset of this data block.
data - The data itself.
off - The offset in the array to begin copying.
len - The number of bytes to copy.
Method Detail

getWriteOffset

public long getWriteOffset()
Description copied from interface: Delta
Get the offset at which this Delta should be written.

Specified by:
getWriteOffset in interface Delta
Returns:
The write offset.

getBlockLength

public int getBlockLength()
Description copied from interface: Delta
The size of the block of data this class represents.

Specified by:
getBlockLength in interface Delta
Returns:
The size of the block of data this class represents.

getOffset

public long getOffset()
Get the offset at which this block should begin.

Returns:
The offset at which this block should begin.
Since:
1.1

getData

public byte[] getData()
Return the array of bytes that is the data block.

Returns:
The block itself.
Since:
1.1

toString

public String toString()
Return a printable string that represents this object.

Overrides:
toString in class Object
Returns:
A string representation of this block.
Since:
1.1

hashCode

public int hashCode()
Return the hash code for this data block.

Overrides:
hashCode in class Object
Returns:
The hash code.
Since:
1.1

equals

public boolean equals(Object o)
Test if another object equals this one.

Overrides:
equals in class Object
Returns:
true If o is an instance of DataBlock and if both the offsets and the byte arrays of both are equal.
Throws:
ClassCastException - If o is not an instance of this class.
NullPointerException - If o is null.