Debian Codegraph @

src/org/tukaani/xz/delta/DeltaDecoder.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 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 // First process from the history buffer.
17 for (int j = Math.min(len, distance); i < j; ++i) {
18 buf[off + i] += history[i];
19 }
20
21 // Then process rest just within buf.
22 for ( ; i < len; ++i) {
23 buf[off + i] += buf[off + i - distance];
24 }
25
26 // Finally, populate the history buffer.
27 if (len >= distance) {
28 System.arraycopy(buf, off + len - distance, history, 0, distance);
29 } else {
30 assert i == len;
31
32 // Copy from the end of the history buffer to the beginning.
33 System.arraycopy(history, i, history, 0, distance - i);
34
35 // Copy all of "in" to the end of the history buffer.
36 System.arraycopy(buf, off, history, distance - i, len);
37 }
38 }
39 }