1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15
16 class PackInputStream extends InputStream {
17 private final WindowCursor wc;
18
19 private final PackFile pack;
20
21 private long pos;
22
23 PackInputStream(PackFile pack, long pos, WindowCursor wc)
24 throws IOException {
25 this.pack = pack;
26 this.pos = pos;
27 this.wc = wc;
28
29
30
31 wc.pin(pack, pos);
32 }
33
34
35 @Override
36 public int read(byte[] b, int off, int len) throws IOException {
37 int n = wc.copy(pack, pos, b, off, len);
38 pos += n;
39 return n;
40 }
41
42
43 @Override
44 public int read() throws IOException {
45 byte[] buf = new byte[1];
46 int n = read(buf, 0, 1);
47 return n == 1 ? buf[0] & 0xff : -1;
48 }
49
50
51 @Override
52 public void close() {
53 wc.close();
54 }
55 }