1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.jgit.internal.storage.file;
14
15 import java.io.IOException;
16 import java.util.zip.CRC32;
17 import java.util.zip.DataFormatException;
18 import java.util.zip.Inflater;
19
20 import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
21
22
23
24
25 final class ByteArrayWindow extends ByteWindow {
26 private final byte[] array;
27
28 ByteArrayWindow(PackFile pack, long o, byte[] b) {
29 super(pack, o, b.length);
30 array = b;
31 }
32
33
34 @Override
35 protected int copy(int p, byte[] b, int o, int n) {
36 n = Math.min(array.length - p, n);
37 System.arraycopy(array, p, b, o, n);
38 return n;
39 }
40
41
42 @Override
43 protected int setInput(int pos, Inflater inf)
44 throws DataFormatException {
45 int n = array.length - pos;
46 inf.setInput(array, pos, n);
47 return n;
48 }
49
50 void crc32(CRC32 out, long pos, int cnt) {
51 out.update(array, (int) (pos - start), cnt);
52 }
53
54 @Override
55 void write(PackOutputStream out, long pos, int cnt)
56 throws IOException {
57 int ptr = (int) (pos - start);
58 out.write(array, ptr, cnt);
59 }
60
61 void check(Inflater inf, byte[] tmp, long pos, int cnt)
62 throws DataFormatException {
63 inf.setInput(array, (int) (pos - start), cnt);
64 while (inf.inflate(tmp, 0, tmp.length) > 0)
65 continue;
66 }
67 }