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