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