package x9; import java.util.zip.CRC32; import java.util.zip.Deflater; /* loaded from: classes2.dex */ public final class k implements u { /* renamed from: a, reason: collision with root package name */ private final d f15480a; /* renamed from: b, reason: collision with root package name */ private final Deflater f15481b; /* renamed from: c, reason: collision with root package name */ private final g f15482c; /* renamed from: d, reason: collision with root package name */ private boolean f15483d; /* renamed from: e, reason: collision with root package name */ private final CRC32 f15484e = new CRC32(); public k(u uVar) { if (uVar == null) { throw new IllegalArgumentException("sink == null"); } Deflater deflater = new Deflater(-1, true); this.f15481b = deflater; d b10 = n.b(uVar); this.f15480a = b10; this.f15482c = new g(b10, deflater); G(); } private void G() { c a10 = this.f15480a.a(); a10.e(8075); a10.h(8); a10.h(0); a10.f(0); a10.h(0); a10.h(0); } private void c(c cVar, long j10) { r rVar = cVar.f15467a; while (j10 > 0) { int min = (int) Math.min(j10, rVar.f15510c - rVar.f15509b); this.f15484e.update(rVar.f15508a, rVar.f15509b, min); j10 -= min; rVar = rVar.f15513f; } } private void z() { this.f15480a.L((int) this.f15484e.getValue()); this.f15480a.L((int) this.f15481b.getBytesRead()); } @Override // x9.u public w b() { return this.f15480a.b(); } @Override // x9.u, java.io.Closeable, java.lang.AutoCloseable public void close() { if (this.f15483d) { return; } try { this.f15482c.z(); z(); th = null; } catch (Throwable th) { th = th; } try { this.f15481b.end(); } catch (Throwable th2) { if (th == null) { th = th2; } } try { this.f15480a.close(); } catch (Throwable th3) { if (th == null) { th = th3; } } this.f15483d = true; if (th != null) { x.e(th); } } @Override // x9.u, java.io.Flushable public void flush() { this.f15482c.flush(); } @Override // x9.u public void t0(c cVar, long j10) { if (j10 < 0) { throw new IllegalArgumentException("byteCount < 0: " + j10); } if (j10 == 0) { return; } c(cVar, j10); this.f15482c.t0(cVar, j10); } }