1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import java.io.BufferedInputStream;
14 import java.io.EOFException;
15 import java.io.IOException;
16 import java.io.InputStream;
17
18 import org.eclipse.jgit.util.NB;
19
20 class XInputStream extends BufferedInputStream {
21 private final byte[] intbuf = new byte[8];
22
23 XInputStream(InputStream s) {
24 super(s);
25 }
26
27 synchronized byte[] readFully(final int len) throws IOException {
28 final byte[] b = new byte[len];
29 readFully(b, 0, len);
30 return b;
31 }
32
33 synchronized void readFully(byte[] b, int o, int len)
34 throws IOException {
35 int r;
36 while (len > 0 && (r = read(b, o, len)) > 0) {
37 o += r;
38 len -= r;
39 }
40 if (len > 0)
41 throw new EOFException();
42 }
43
44 int readUInt8() throws IOException {
45 final int r = read();
46 if (r < 0)
47 throw new EOFException();
48 return r;
49 }
50
51 long readUInt32() throws IOException {
52 readFully(intbuf, 0, 4);
53 return NB.decodeUInt32(intbuf, 0);
54 }
55 }