package com.google.android.play.core.assetpacks; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; /* loaded from: classes2.dex */ final class g1 extends OutputStream { /* renamed from: a, reason: collision with root package name */ private final g2 f4884a = new g2(); /* renamed from: b, reason: collision with root package name */ private final File f4885b; /* renamed from: c, reason: collision with root package name */ private final b3 f4886c; /* renamed from: d, reason: collision with root package name */ private long f4887d; /* renamed from: e, reason: collision with root package name */ private long f4888e; /* renamed from: f, reason: collision with root package name */ private FileOutputStream f4889f; /* renamed from: g, reason: collision with root package name */ private h3 f4890g; g1(File file, b3 b3Var) { this.f4885b = file; this.f4886c = b3Var; } @Override // java.io.OutputStream public final void write(int i10) { write(new byte[]{(byte) i10}, 0, 1); } @Override // java.io.OutputStream public final void write(byte[] bArr) { write(bArr, 0, bArr.length); } @Override // java.io.OutputStream public final void write(byte[] bArr, int i10, int i11) { int min; while (i11 > 0) { if (this.f4887d == 0 && this.f4888e == 0) { int b10 = this.f4884a.b(bArr, i10, i11); if (b10 == -1) { return; } i10 += b10; i11 -= b10; h3 c10 = this.f4884a.c(); this.f4890g = c10; if (c10.d()) { this.f4887d = 0L; this.f4886c.l(this.f4890g.f(), 0, this.f4890g.f().length); this.f4888e = this.f4890g.f().length; } else if (this.f4890g.h() && !this.f4890g.g()) { this.f4886c.j(this.f4890g.f()); File file = new File(this.f4885b, this.f4890g.c()); file.getParentFile().mkdirs(); this.f4887d = this.f4890g.b(); this.f4889f = new FileOutputStream(file); } else { byte[] f10 = this.f4890g.f(); this.f4886c.l(f10, 0, f10.length); this.f4887d = this.f4890g.b(); } } if (!this.f4890g.g()) { long j10 = i11; if (this.f4890g.d()) { this.f4886c.e(this.f4888e, bArr, i10, i11); this.f4888e += j10; min = i11; } else if (this.f4890g.h()) { min = (int) Math.min(j10, this.f4887d); this.f4889f.write(bArr, i10, min); long j11 = this.f4887d - min; this.f4887d = j11; if (j11 == 0) { this.f4889f.close(); } } else { min = (int) Math.min(j10, this.f4887d); this.f4886c.e((this.f4890g.f().length + this.f4890g.b()) - this.f4887d, bArr, i10, min); this.f4887d -= min; } i10 += min; i11 -= min; } } } }