package g0; import androidx.recyclerview.widget.RecyclerView; 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.f2885c; 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.f2885c - 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 i0(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.s("byteCount < 0: ", j).toString()); } else if (i == 0) { return 0; } else { if (this.i == 0) { this.j.p0(10); byte q = this.j.i.q(3); boolean z3 = ((q >> 1) & 1) == 1; if (z3) { b(this.j.i, 0, 10); } a("ID1ID2", 8075, this.j.readShort()); this.j.skip(8); if (((q >> 2) & 1) == 1) { this.j.p0(2); if (z3) { b(this.j.i, 0, 2); } long y2 = (long) this.j.i.y(); this.j.p0(y2); if (z3) { j2 = y2; b(this.j.i, 0, y2); } else { j2 = y2; } this.j.skip(j2); } if (((q >> 3) & 1) == 1) { long a = this.j.a((byte) 0, 0, RecyclerView.FOREVER_NS); if (a != -1) { if (z3) { b(this.j.i, 0, a + 1); } this.j.skip(a + 1); } else { throw new EOFException(); } } if (((q >> 4) & 1) == 1) { z2 = true; } if (z2) { long a2 = this.j.a((byte) 0, 0, RecyclerView.FOREVER_NS); 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.p0(2); a("FHCRC", rVar.i.y(), (short) ((int) this.m.getValue())); this.m.reset(); } this.i = 1; } if (this.i == 1) { long j3 = eVar.j; long i02 = this.l.i0(eVar, j); if (i02 != -1) { b(eVar, j3, i02); return i02; } 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.w()) { throw new IOException("gzip finished without exhausting source"); } } return -1; } } @Override // g0.x public y timeout() { return this.j.timeout(); } }