what-the-bank/sources/o/fNQ.java

167 lines
4.1 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package o;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes.dex */
final class fNQ extends InputStream {
boolean a;
private long b;
private long c;
private final InputStream d;
private int e;
private long g;
private long i;
/* JADX INFO: Access modifiers changed from: package-private */
public fNQ(InputStream inputStream) {
this(inputStream, (byte) 0);
}
private fNQ(InputStream inputStream, byte b) {
this(inputStream, (char) 0);
}
private fNQ(InputStream inputStream, char c) {
this.b = -1L;
this.a = true;
this.e = -1;
this.d = inputStream.markSupported() ? inputStream : new BufferedInputStream(inputStream, 4096);
this.e = 1024;
}
@Override // java.io.InputStream
public final void mark(int i) {
this.b = c(i);
}
public final long c(int i) {
long j = this.i + i;
if (this.c < j) {
b(j);
}
return this.i;
}
private void b(long j) {
try {
long j2 = this.g;
long j3 = this.i;
if (j2 < j3 && j3 <= this.c) {
this.d.reset();
this.d.mark((int) (j - this.g));
c(this.g, this.i);
} else {
this.g = j3;
this.d.mark((int) (j - j3));
}
this.c = j;
} catch (IOException e) {
throw new IllegalStateException("Unable to mark: ".concat(String.valueOf(e)));
}
}
@Override // java.io.InputStream
public final void reset() throws IOException {
e(this.b);
}
public final void e(long j) throws IOException {
if (this.i > this.c || j < this.g) {
throw new IOException("Cannot reset");
}
this.d.reset();
c(this.g, j);
this.i = j;
}
private void c(long j, long j2) throws IOException {
while (j < j2) {
long skip = this.d.skip(j2 - j);
if (skip == 0) {
if (read() == -1) {
return;
} else {
skip = 1;
}
}
j += skip;
}
}
@Override // java.io.InputStream
public final int read() throws IOException {
if (!this.a) {
long j = this.i;
long j2 = this.c;
if (j + 1 > j2) {
b(j2 + this.e);
}
}
int read = this.d.read();
if (read != -1) {
this.i++;
}
return read;
}
@Override // java.io.InputStream
public final int read(byte[] bArr) throws IOException {
if (!this.a) {
long j = this.i;
if (bArr.length + j > this.c) {
b(j + bArr.length + this.e);
}
}
int read = this.d.read(bArr);
if (read != -1) {
this.i += read;
}
return read;
}
@Override // java.io.InputStream
public final int read(byte[] bArr, int i, int i2) throws IOException {
if (!this.a) {
long j = this.i + i2;
if (j > this.c) {
b(j + this.e);
}
}
int read = this.d.read(bArr, i, i2);
if (read != -1) {
this.i += read;
}
return read;
}
@Override // java.io.InputStream
public final long skip(long j) throws IOException {
if (!this.a) {
long j2 = this.i + j;
if (j2 > this.c) {
b(j2 + this.e);
}
}
long skip = this.d.skip(j);
this.i += skip;
return skip;
}
@Override // java.io.InputStream
public final int available() throws IOException {
return this.d.available();
}
@Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
this.d.close();
}
@Override // java.io.InputStream
public final boolean markSupported() {
return this.d.markSupported();
}
}