package t9; import com.google.android.gms.common.api.Api; import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import t9.d; /* loaded from: classes2.dex */ final class j implements Closeable { /* renamed from: g, reason: collision with root package name */ private static final Logger f14618g = Logger.getLogger(e.class.getName()); /* renamed from: a, reason: collision with root package name */ private final x9.d f14619a; /* renamed from: b, reason: collision with root package name */ private final boolean f14620b; /* renamed from: c, reason: collision with root package name */ private final x9.c f14621c; /* renamed from: d, reason: collision with root package name */ private int f14622d; /* renamed from: e, reason: collision with root package name */ private boolean f14623e; /* renamed from: f, reason: collision with root package name */ final d.b f14624f; j(x9.d dVar, boolean z10) { this.f14619a = dVar; this.f14620b = z10; x9.c cVar = new x9.c(); this.f14621c = cVar; this.f14624f = new d.b(cVar); this.f14622d = 16384; } private void m0(int i10, long j10) { while (j10 > 0) { int min = (int) Math.min(this.f14622d, j10); long j11 = min; j10 -= j11; O(i10, min, (byte) 9, j10 == 0 ? (byte) 4 : (byte) 0); this.f14619a.t0(this.f14621c, j11); } } private static void n0(x9.d dVar, int i10) { dVar.h((i10 >>> 16) & 255); dVar.h((i10 >>> 8) & 255); dVar.h(i10 & 255); } public synchronized void G(boolean z10, int i10, x9.c cVar, int i11) { if (this.f14623e) { throw new IOException("closed"); } I(i10, z10 ? (byte) 1 : (byte) 0, cVar, i11); } void I(int i10, byte b10, x9.c cVar, int i11) { O(i10, i11, (byte) 0, b10); if (i11 > 0) { this.f14619a.t0(cVar, i11); } } public void O(int i10, int i11, byte b10, byte b11) { Logger logger = f14618g; if (logger.isLoggable(Level.FINE)) { logger.fine(e.b(false, i10, i11, b10, b11)); } int i12 = this.f14622d; if (i11 > i12) { throw e.c("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(i12), Integer.valueOf(i11)); } if ((Integer.MIN_VALUE & i10) != 0) { throw e.c("reserved bit set: %s", Integer.valueOf(i10)); } n0(this.f14619a, i11); this.f14619a.h(b10 & 255); this.f14619a.h(b11 & 255); this.f14619a.f(i10 & Api.BaseClientBuilder.API_PRIORITY_OTHER); } public synchronized void P(int i10, b bVar, byte[] bArr) { if (this.f14623e) { throw new IOException("closed"); } if (bVar.f14470a == -1) { throw e.c("errorCode.httpCode == -1", new Object[0]); } O(0, bArr.length + 8, (byte) 7, (byte) 0); this.f14619a.f(i10); this.f14619a.f(bVar.f14470a); if (bArr.length > 0) { this.f14619a.q(bArr); } this.f14619a.flush(); } public synchronized void R(boolean z10, int i10, List list) { if (this.f14623e) { throw new IOException("closed"); } this.f14624f.g(list); long u02 = this.f14621c.u0(); int min = (int) Math.min(this.f14622d, u02); long j10 = min; byte b10 = u02 == j10 ? (byte) 4 : (byte) 0; if (z10) { b10 = (byte) (b10 | 1); } O(i10, min, (byte) 1, b10); this.f14619a.t0(this.f14621c, j10); if (u02 > j10) { m0(i10, u02 - j10); } } public int S() { return this.f14622d; } public synchronized void Y(boolean z10, int i10, int i11) { if (this.f14623e) { throw new IOException("closed"); } O(0, 8, (byte) 6, z10 ? (byte) 1 : (byte) 0); this.f14619a.f(i10); this.f14619a.f(i11); this.f14619a.flush(); } public synchronized void a0(int i10, int i11, List list) { if (this.f14623e) { throw new IOException("closed"); } this.f14624f.g(list); long u02 = this.f14621c.u0(); int min = (int) Math.min(this.f14622d - 4, u02); long j10 = min; O(i10, min + 4, (byte) 5, u02 == j10 ? (byte) 4 : (byte) 0); this.f14619a.f(i11 & Api.BaseClientBuilder.API_PRIORITY_OTHER); this.f14619a.t0(this.f14621c, j10); if (u02 > j10) { m0(i10, u02 - j10); } } public synchronized void c(m mVar) { if (this.f14623e) { throw new IOException("closed"); } this.f14622d = mVar.f(this.f14622d); if (mVar.c() != -1) { this.f14624f.e(mVar.c()); } O(0, 0, (byte) 4, (byte) 1); this.f14619a.flush(); } @Override // java.io.Closeable, java.lang.AutoCloseable public synchronized void close() { this.f14623e = true; this.f14619a.close(); } public synchronized void d0(int i10, b bVar) { if (this.f14623e) { throw new IOException("closed"); } if (bVar.f14470a == -1) { throw new IllegalArgumentException(); } O(i10, 4, (byte) 3, (byte) 0); this.f14619a.f(bVar.f14470a); this.f14619a.flush(); } public synchronized void f0(m mVar) { if (this.f14623e) { throw new IOException("closed"); } int i10 = 0; O(0, mVar.j() * 6, (byte) 4, (byte) 0); while (i10 < 10) { if (mVar.g(i10)) { this.f14619a.e(i10 == 4 ? 3 : i10 == 7 ? 4 : i10); this.f14619a.f(mVar.b(i10)); } i10++; } this.f14619a.flush(); } public synchronized void flush() { if (this.f14623e) { throw new IOException("closed"); } this.f14619a.flush(); } public synchronized void j0(int i10, long j10) { if (this.f14623e) { throw new IOException("closed"); } if (j10 == 0 || j10 > 2147483647L) { throw e.c("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j10)); } O(i10, 4, (byte) 8, (byte) 0); this.f14619a.f((int) j10); this.f14619a.flush(); } public synchronized void z() { if (this.f14623e) { throw new IOException("closed"); } if (this.f14620b) { Logger logger = f14618g; if (logger.isLoggable(Level.FINE)) { logger.fine(o9.e.q(">> CONNECTION %s", e.f14500a.i())); } this.f14619a.q(e.f14500a.r()); this.f14619a.flush(); } } }