69 lines
2.0 KiB
Java
69 lines
2.0 KiB
Java
|
package com.google.common.io;
|
||
|
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import java.io.FilterInputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class CountingInputStream extends FilterInputStream {
|
||
|
private long count;
|
||
|
private long mark;
|
||
|
|
||
|
public CountingInputStream(InputStream inputStream) {
|
||
|
super((InputStream) Preconditions.checkNotNull(inputStream));
|
||
|
this.mark = -1L;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.FilterInputStream, java.io.InputStream
|
||
|
public final int read() throws IOException {
|
||
|
int read = ((FilterInputStream) this).in.read();
|
||
|
if (read != -1) {
|
||
|
this.count++;
|
||
|
}
|
||
|
return read;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.FilterInputStream, java.io.InputStream
|
||
|
public final int read(byte[] bArr, int i, int i2) throws IOException {
|
||
|
int read = ((FilterInputStream) this).in.read(bArr, i, i2);
|
||
|
if (read != -1) {
|
||
|
this.count += read;
|
||
|
}
|
||
|
return read;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.FilterInputStream, java.io.InputStream
|
||
|
public final long skip(long j) throws IOException {
|
||
|
long skip = ((FilterInputStream) this).in.skip(j);
|
||
|
this.count += skip;
|
||
|
return skip;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.FilterInputStream, java.io.InputStream
|
||
|
public final void mark(int i) {
|
||
|
synchronized (this) {
|
||
|
((FilterInputStream) this).in.mark(i);
|
||
|
this.mark = this.count;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // java.io.FilterInputStream, java.io.InputStream
|
||
|
public final void reset() throws IOException {
|
||
|
synchronized (this) {
|
||
|
if (!((FilterInputStream) this).in.markSupported()) {
|
||
|
throw new IOException("Mark not supported");
|
||
|
}
|
||
|
if (this.mark == -1) {
|
||
|
throw new IOException("Mark not set");
|
||
|
}
|
||
|
((FilterInputStream) this).in.reset();
|
||
|
this.count = this.mark;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final long getCount() {
|
||
|
return this.count;
|
||
|
}
|
||
|
}
|