package h5; 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 y implements o0 { /* renamed from: b, reason: collision with root package name */ private final f f10323b; /* renamed from: c, reason: collision with root package name */ private final Inflater f10324c; /* renamed from: d, reason: collision with root package name */ private final c0 f10325d; /* renamed from: a, reason: collision with root package name */ private int f10322a = 0; /* renamed from: e, reason: collision with root package name */ private final CRC32 f10326e = new CRC32(); public y(o0 o0Var) { if (o0Var == null) { throw new IllegalArgumentException("source == null"); } Inflater inflater = new Inflater(true); this.f10324c = inflater; f f10 = g0.f(o0Var); this.f10323b = f10; this.f10325d = new c0(f10, inflater); } private void G(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 I() { G("CRC", this.f10323b.o(), (int) this.f10326e.getValue()); G("ISIZE", this.f10323b.o(), (int) this.f10324c.getBytesWritten()); } private void c() { this.f10323b.s(10L); byte a02 = this.f10323b.a().a0(3L); boolean z10 = ((a02 >> 1) & 1) == 1; if (z10) { z(this.f10323b.a(), 0L, 10L); } G("ID1ID2", 8075, this.f10323b.readShort()); this.f10323b.skip(8L); if (((a02 >> 2) & 1) == 1) { this.f10323b.s(2L); if (z10) { z(this.f10323b.a(), 0L, 2L); } long r10 = this.f10323b.a().r(); this.f10323b.s(r10); if (z10) { z(this.f10323b.a(), 0L, r10); } this.f10323b.skip(r10); } if (((a02 >> 3) & 1) == 1) { long t10 = this.f10323b.t((byte) 0); if (t10 == -1) { throw new EOFException(); } if (z10) { z(this.f10323b.a(), 0L, t10 + 1); } this.f10323b.skip(t10 + 1); } if (((a02 >> 4) & 1) == 1) { long t11 = this.f10323b.t((byte) 0); if (t11 == -1) { throw new EOFException(); } if (z10) { z(this.f10323b.a(), 0L, t11 + 1); } this.f10323b.skip(t11 + 1); } if (z10) { G("FHCRC", this.f10323b.r(), (short) this.f10326e.getValue()); this.f10326e.reset(); } } private void z(d dVar, long j10, long j11) { v0 v0Var = dVar.f10013a; while (true) { long j12 = v0Var.f10311c - v0Var.f10310b; if (j10 < j12) { break; } j10 -= j12; v0Var = v0Var.f10314f; } while (j11 > 0) { int min = (int) Math.min(v0Var.f10311c - r6, j11); this.f10326e.update(v0Var.f10309a, (int) (v0Var.f10310b + j10), min); j11 -= min; v0Var = v0Var.f10314f; j10 = 0; } } @Override // h5.o0 public long H(d dVar, long j10) { if (j10 < 0) { throw new IllegalArgumentException("byteCount < 0: " + j10); } if (j10 == 0) { return 0L; } if (this.f10322a == 0) { c(); this.f10322a = 1; } if (this.f10322a == 1) { long j11 = dVar.f10014b; long H = this.f10325d.H(dVar, j10); if (H != -1) { z(dVar, j11, H); return H; } this.f10322a = 2; } if (this.f10322a == 2) { I(); this.f10322a = 3; if (!this.f10323b.g()) { throw new IOException("gzip finished without exhausting source"); } } return -1L; } @Override // h5.o0 public p0 b() { return this.f10323b.b(); } @Override // h5.o0, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f10325d.close(); } }