Debian Codegraph @

src/org/tukaani/xz/delta/DeltaEncoder.java

raw symbols SCIP
1 // SPDX-License-Identifier: 0BSD
2 // SPDX-FileCopyrightText: The XZ for Java authors and contributors
3 // SPDX-FileContributor: Lasse Collin <[email protected]>
4 // SPDX-FileContributor: Brett Okken <[email protected]>
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 // First deal with comparisons to the history buffer.
17 for (int j = Math.min(len, distance); i < j; ++i) {
18 out[i] = (byte)(in[in_off + i] - history[i]);
19 }
20
21 // Now fill the history buffer with the last "distance" number of
22 // bytes from the input buffer.
23 if (len >= distance) {
24 System.arraycopy(in, in_off + len - distance, history, 0,
25 distance);
26 } else {
27 assert i == len;
28
29 // Copy from the end of the history buffer to the beginning.
30 System.arraycopy(history, i, history, 0, distance - i);
31
32 // Copy all of "in" to the end of the history buffer.
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 }