package g0; import c.d.b.a.a; import d0.z.d.m; import java.io.EOFException; import java.io.IOException; import java.util.Arrays; import java.util.zip.CRC32; import java.util.zip.Inflater; /* compiled from: GzipSource.kt */ public final class l implements x { public byte i; public final r j; public final Inflater k; public final m l; public final CRC32 m = new CRC32(); public l(x xVar) { m.checkParameterIsNotNull(xVar, "source"); r rVar = new r(xVar); this.j = rVar; Inflater inflater = new Inflater(true); this.k = inflater; this.l = new m((g) rVar, inflater); } public final void a(String str, int i, int i2) { if (i2 != i) { String format = String.format("%s: actual 0x%08x != expected 0x%08x", Arrays.copyOf(new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)}, 3)); m.checkExpressionValueIsNotNull(format, "java.lang.String.format(this, *args)"); throw new IOException(format); } } public final void b(e eVar, long j, long j2) { s sVar = eVar.i; if (sVar == null) { m.throwNpe(); } while (true) { int i = sVar.f2789c; int i2 = sVar.b; if (j < ((long) (i - i2))) { break; } j -= (long) (i - i2); sVar = sVar.f; if (sVar == null) { m.throwNpe(); } } while (j2 > 0) { int i3 = (int) (((long) sVar.b) + j); int min = (int) Math.min((long) (sVar.f2789c - i3), j2); this.m.update(sVar.a, i3, min); j2 -= (long) min; sVar = sVar.f; if (sVar == null) { m.throwNpe(); } j = 0; } } @Override // g0.x, java.io.Closeable, java.lang.AutoCloseable public void close() throws IOException { this.l.close(); } @Override // g0.x public long h0(e eVar, long j) throws IOException { long j2; m.checkParameterIsNotNull(eVar, "sink"); boolean z2 = false; int i = (j > 0 ? 1 : (j == 0 ? 0 : -1)); if (!(i >= 0)) { throw new IllegalArgumentException(a.o("byteCount < 0: ", j).toString()); } else if (i == 0) { return 0; } else { if (this.i == 0) { this.j.o0(10); byte r = this.j.i.r(3); boolean z3 = ((r >> 1) & 1) == 1; if (z3) { b(this.j.i, 0, 10); } a("ID1ID2", 8075, this.j.readShort()); this.j.skip(8); if (((r >> 2) & 1) == 1) { this.j.o0(2); if (z3) { b(this.j.i, 0, 2); } long z4 = (long) this.j.i.z(); this.j.o0(z4); if (z3) { j2 = z4; b(this.j.i, 0, z4); } else { j2 = z4; } this.j.skip(j2); } if (((r >> 3) & 1) == 1) { long a = this.j.a((byte) 0, 0, Long.MAX_VALUE); if (a != -1) { if (z3) { b(this.j.i, 0, a + 1); } this.j.skip(a + 1); } else { throw new EOFException(); } } if (((r >> 4) & 1) == 1) { z2 = true; } if (z2) { long a2 = this.j.a((byte) 0, 0, Long.MAX_VALUE); if (a2 != -1) { if (z3) { b(this.j.i, 0, a2 + 1); } this.j.skip(a2 + 1); } else { throw new EOFException(); } } if (z3) { r rVar = this.j; rVar.o0(2); a("FHCRC", rVar.i.z(), (short) ((int) this.m.getValue())); this.m.reset(); } this.i = 1; } if (this.i == 1) { long j3 = eVar.j; long h02 = this.l.h0(eVar, j); if (h02 != -1) { b(eVar, j3, h02); return h02; } this.i = 2; } if (this.i == 2) { a("CRC", this.j.b(), (int) this.m.getValue()); a("ISIZE", this.j.b(), (int) this.k.getBytesWritten()); this.i = 3; if (!this.j.v()) { throw new IOException("gzip finished without exhausting source"); } } return -1; } } @Override // g0.x public y timeout() { return this.j.timeout(); } }