1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.util.io;
12
13 import java.io.IOException;
14 import java.io.OutputStream;
15
16
17
18
19 public class CountingOutputStream extends OutputStream {
20 private final OutputStream out;
21 private long cnt;
22
23
24
25
26
27
28
29 public CountingOutputStream(OutputStream out) {
30 this.out = out;
31 }
32
33
34
35
36
37
38 public long getCount() {
39 return cnt;
40 }
41
42
43 @Override
44 public void write(int val) throws IOException {
45 out.write(val);
46 cnt++;
47 }
48
49
50 @Override
51 public void write(byte[] buf, int off, int len) throws IOException {
52 out.write(buf, off, len);
53 cnt += len;
54 }
55
56
57 @Override
58 public void flush() throws IOException {
59 out.flush();
60 }
61
62
63 @Override
64 public void close() throws IOException {
65 out.close();
66 }
67 }