package x9; import java.util.zip.Deflater; /* loaded from: classes2.dex */ public final class g implements u { /* renamed from: a, reason: collision with root package name */ private final d f15474a; /* renamed from: b, reason: collision with root package name */ private final Deflater f15475b; /* renamed from: c, reason: collision with root package name */ private boolean f15476c; g(d dVar, Deflater deflater) { if (dVar == null) { throw new IllegalArgumentException("source == null"); } if (deflater == null) { throw new IllegalArgumentException("inflater == null"); } this.f15474a = dVar; this.f15475b = deflater; } private void c(boolean z10) { r D0; int deflate; c a10 = this.f15474a.a(); while (true) { D0 = a10.D0(1); if (z10) { Deflater deflater = this.f15475b; byte[] bArr = D0.f15508a; int i10 = D0.f15510c; deflate = deflater.deflate(bArr, i10, 8192 - i10, 2); } else { Deflater deflater2 = this.f15475b; byte[] bArr2 = D0.f15508a; int i11 = D0.f15510c; deflate = deflater2.deflate(bArr2, i11, 8192 - i11); } if (deflate > 0) { D0.f15510c += deflate; a10.f15468b += deflate; this.f15474a.Q(); } else if (this.f15475b.needsInput()) { break; } } if (D0.f15509b == D0.f15510c) { a10.f15467a = D0.b(); s.a(D0); } } @Override // x9.u public w b() { return this.f15474a.b(); } @Override // x9.u, java.io.Closeable, java.lang.AutoCloseable public void close() { if (this.f15476c) { return; } try { z(); th = null; } catch (Throwable th) { th = th; } try { this.f15475b.end(); } catch (Throwable th2) { if (th == null) { th = th2; } } try { this.f15474a.close(); } catch (Throwable th3) { if (th == null) { th = th3; } } this.f15476c = true; if (th != null) { x.e(th); } } @Override // x9.u, java.io.Flushable public void flush() { c(true); this.f15474a.flush(); } @Override // x9.u public void t0(c cVar, long j10) { x.b(cVar.f15468b, 0L, j10); while (j10 > 0) { r rVar = cVar.f15467a; int min = (int) Math.min(j10, rVar.f15510c - rVar.f15509b); this.f15475b.setInput(rVar.f15508a, rVar.f15509b, min); c(false); long j11 = min; cVar.f15468b -= j11; int i10 = rVar.f15509b + min; rVar.f15509b = i10; if (i10 == rVar.f15510c) { cVar.f15467a = rVar.b(); s.a(rVar); } j10 -= j11; } } public String toString() { return "DeflaterSink(" + this.f15474a + ")"; } void z() { this.f15475b.finish(); c(false); } }