| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package org.tukaani.xz.delta; |
| 7 |
|
| 8 |
public class DeltaEncoder extends DeltaCoder { |
| 9 |
public DeltaEncoder(int distance) { |
| 10 |
super(distance); |
| 11 |
} |
| 12 |
|
| 13 |
public void encode(byte[] in, int in_off, int len, byte[] out) { |
| 14 |
int i = 0; |
| 15 |
|
| 16 |
|
| 17 |
for (int j = Math.min(len, distance); i < j; ++i) { |
| 18 |
out[i] = (byte)(in[in_off + i] - history[i]); |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
if (len >= distance) { |
| 24 |
System.arraycopy(in, in_off + len - distance, history, 0, |
| 25 |
distance); |
| 26 |
} else { |
| 27 |
assert i == len; |
| 28 |
|
| 29 |
|
| 30 |
System.arraycopy(history, i, history, 0, distance - i); |
| 31 |
|
| 32 |
|
| 33 |
System.arraycopy(in, in_off, history, distance - i, len); |
| 34 |
} |
| 35 |
|
| 36 |
for ( ; i < len; ++i) { |
| 37 |
out[i] = (byte)(in[in_off + i] - in[in_off + i - distance]); |
| 38 |
} |
| 39 |
} |
| 40 |
} |