TrackingInputStream.java
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Decompiled with CFR 0_118.
*/
package com.day.crx.packaging;
import com.day.crx.packaging.ProxyTracker;
import java.io.IOException;
import java.io.InputStream;
public class TrackingInputStream
extends InputStream {
private final InputStream base;
private final long length;
private long count = 0;
private final ProxyTracker tracker;
public TrackingInputStream(InputStream base, long length, ProxyTracker tracker) {
this.base = base;
this.length = length;
this.tracker = tracker;
}
@Override
public int read(byte[] bytes) throws IOException {
int ret = this.base.read(bytes);
if (ret >= 0) {
this.count += (long)ret;
this.tracker.onProgress(this.count, this.length);
}
return ret;
}
@Override
public int read(byte[] bytes, int i, int i1) throws IOException {
int ret = this.base.read(bytes, i, i1);
if (ret >= 0) {
this.count += (long)ret;
this.tracker.onProgress(this.count, this.length);
}
return ret;
}
@Override
public int read() throws IOException {
int ret = this.base.read();
if (ret >= 0) {
this.tracker.onProgress(this.count++, this.length);
}
return ret;
}
@Override
public long skip(long l) throws IOException {
long ret = this.base.skip(l);
if (ret >= 0) {
this.count += ret;
this.tracker.onProgress(this.count, this.length);
}
return ret;
}
}