RangedInputStream.java
1.24 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.io;
import com.adobe.internal.io.CountingInputStream;
import java.io.IOException;
import java.io.InputStream;
public class RangedInputStream
extends CountingInputStream {
private final long length;
private boolean closed;
public RangedInputStream(InputStream in, long length) {
super(in);
this.length = length;
}
@Override
public int read() throws IOException {
if (this.closed || this.getOffset() == this.length) {
return -1;
}
return super.read();
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (this.closed || this.getOffset() == this.length) {
return -1;
}
len = (int)Math.min(this.length - this.getOffset(), (long)len);
return super.read(b, off, len);
}
@Override
public int read(byte[] b) throws IOException {
return this.read(b, 0, b.length);
}
@Override
public long skip(long n) throws IOException {
n = Math.min(this.length - this.getOffset(), n);
return super.skip(n);
}
@Override
public void close() throws IOException {
this.closed = true;
}
}