MCPcopy Create free account
hub / github.com/e2wugui/zeze / Decompress

Class Decompress

ZezeJava/ZezeJava/src/main/java/Zeze/Net/Decompress.java:6–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5// RFC2118
6public class Decompress implements Codec {
7 protected final @NotNull Codec sink;
8 protected int rem;
9 protected int pos;
10 protected int off = -1;
11 private final byte[] hist = new byte[8192 * 3];
12 private int hpos;
13
14 public static class DecompressException extends CodecException {
15 }
16
17 public Decompress(@NotNull Codec sink) {
18 this.sink = sink;
19 }
20
21 private void drain() {
22 if (hpos >= 8192 * 2) {
23 System.arraycopy(hist, hpos - 8192, hist, 0, 8192);
24 hpos = 8192;
25 }
26 }
27
28 private void copy(int dstPos, int srcPos, int length) {
29 for (int i = 0; i < length; i++)
30 hist[dstPos++] = hist[srcPos++];
31 }
32
33 private void output(byte c) throws CodecException {
34 sink.update(hist[hpos++] = c);
35 drain();
36 }
37
38 private void output(int off, int len) throws CodecException {
39 if (hpos < off)
40 throw new DecompressException();
41 copy(hpos, hpos - off, len);
42 sink.update(hist, hpos, len);
43 hpos += len;
44 drain();
45 }
46
47 private int bitCompute() {
48 long val = ((long)rem << (32 - pos)) & 0xffff_ffffL;
49 if (off < 0) {
50 if (val < 0x8000_0000L)
51 return 8;
52 if (val < 0xc000_0000L)
53 return 9;
54 if (val < 0xe000_0000L)
55 return 16;
56 if (val < 0xf000_0000L)
57 return 12;
58 return 10;
59 }
60 if (val < 0x8000_0000L)
61 return 1;
62 if (val < 0xc000_0000L)
63 return 4;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected