SizedInputStream.java
1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Decompiled with CFR 0_118.
*/
package com.day.io.file;
import java.io.IOException;
import java.io.InputStream;
public class SizedInputStream
extends InputStream {
private final InputStream in;
private final int max;
private int pos = 0;
private int mark = -1;
public SizedInputStream(InputStream in, int size) {
this.max = size < 0 ? 0 : size;
this.in = in;
}
private int bytesLeft() {
return this.max - this.pos;
}
public int read() throws IOException {
if (this.pos == this.max) {
return -1;
}
int result = this.in.read();
++this.pos;
return result;
}
public int read(byte[] b) throws IOException {
return this.read(b, 0, b.length);
}
public int read(byte[] b, int off, int len) throws IOException {
if (this.pos >= this.max) {
return -1;
}
int maxRead = Math.min(len, this.bytesLeft());
int bytesRead = this.in.read(b, off, maxRead);
if (bytesRead == -1) {
return -1;
}
this.pos += bytesRead;
return bytesRead;
}
public long skip(long n) throws IOException {
long skippedBytes = this.in.skip(Math.min(n, (long)this.bytesLeft()));
this.pos = (int)((long)this.pos + skippedBytes);
return skippedBytes;
}
public int available() throws IOException {
if (this.pos >= this.max) {
return 0;
}
return this.in.available();
}
public String toString() {
return this.in.toString();
}
public void close() throws IOException {
this.in.close();
}
public synchronized void reset() throws IOException {
this.in.reset();
this.pos = this.mark;
}
public synchronized void mark(int readlimit) {
this.in.mark(readlimit);
this.mark = this.pos;
}
public boolean markSupported() {
return this.in.markSupported();
}
}