package x9; import java.io.EOFException; import java.io.IOException; import java.util.zip.CRC32; import java.util.zip.Inflater; /* loaded from: classes2.dex */ public final class l implements v { /* renamed from: b, reason: collision with root package name */ private final e f15486b; /* renamed from: c, reason: collision with root package name */ private final Inflater f15487c; /* renamed from: d, reason: collision with root package name */ private final m f15488d; /* renamed from: a, reason: collision with root package name */ private int f15485a = 0; /* renamed from: e, reason: collision with root package name */ private final CRC32 f15489e = new CRC32(); public l(v vVar) { if (vVar == null) { throw new IllegalArgumentException("source == null"); } Inflater inflater = new Inflater(true); this.f15487c = inflater; e c10 = n.c(vVar); this.f15486b = c10; this.f15488d = new m(c10, inflater); } private void G() { c("CRC", this.f15486b.o(), (int) this.f15489e.getValue()); c("ISIZE", this.f15486b.o(), (int) this.f15487c.getBytesWritten()); } private void I(c cVar, long j10, long j11) { r rVar = cVar.f15467a; while (true) { int i10 = rVar.f15510c; int i11 = rVar.f15509b; if (j10 < i10 - i11) { break; } j10 -= i10 - i11; rVar = rVar.f15513f; } while (j11 > 0) { int min = (int) Math.min(rVar.f15510c - r7, j11); this.f15489e.update(rVar.f15508a, (int) (rVar.f15509b + j10), min); j11 -= min; rVar = rVar.f15513f; j10 = 0; } } private void c(String str, int i10, int i11) { if (i11 != i10) { throw new IOException(String.format("%s: actual 0x%08x != expected 0x%08x", str, Integer.valueOf(i11), Integer.valueOf(i10))); } } private void z() { this.f15486b.s(10L); byte Y = this.f15486b.a().Y(3L); boolean z10 = ((Y >> 1) & 1) == 1; if (z10) { I(this.f15486b.a(), 0L, 10L); } c("ID1ID2", 8075, this.f15486b.readShort()); this.f15486b.skip(8L); if (((Y >> 2) & 1) == 1) { this.f15486b.s(2L); if (z10) { I(this.f15486b.a(), 0L, 2L); } long r10 = this.f15486b.a().r(); this.f15486b.s(r10); if (z10) { I(this.f15486b.a(), 0L, r10); } this.f15486b.skip(r10); } if (((Y >> 3) & 1) == 1) { long t10 = this.f15486b.t((byte) 0); if (t10 == -1) { throw new EOFException(); } if (z10) { I(this.f15486b.a(), 0L, t10 + 1); } this.f15486b.skip(t10 + 1); } if (((Y >> 4) & 1) == 1) { long t11 = this.f15486b.t((byte) 0); if (t11 == -1) { throw new EOFException(); } if (z10) { I(this.f15486b.a(), 0L, t11 + 1); } this.f15486b.skip(t11 + 1); } if (z10) { c("FHCRC", this.f15486b.r(), (short) this.f15489e.getValue()); this.f15489e.reset(); } } @Override // x9.v public w b() { return this.f15486b.b(); } @Override // x9.v, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f15488d.close(); } @Override // x9.v public long s0(c cVar, long j10) { if (j10 < 0) { throw new IllegalArgumentException("byteCount < 0: " + j10); } if (j10 == 0) { return 0L; } if (this.f15485a == 0) { z(); this.f15485a = 1; } if (this.f15485a == 1) { long j11 = cVar.f15468b; long s02 = this.f15488d.s0(cVar, j10); if (s02 != -1) { I(cVar, j11, s02); return s02; } this.f15485a = 2; } if (this.f15485a == 2) { G(); this.f15485a = 3; if (!this.f15486b.g()) { throw new IOException("gzip finished without exhausting source"); } } return -1L; } }