package n5; 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 n5.k; /* loaded from: classes2.dex */ final class m implements Closeable { /* renamed from: g, reason: collision with root package name */ private static final Logger f12140g = Logger.getLogger(d.class.getName()); /* renamed from: a, reason: collision with root package name */ private final h5.e f12141a; /* renamed from: b, reason: collision with root package name */ private final boolean f12142b; /* renamed from: c, reason: collision with root package name */ private final h5.d f12143c; /* renamed from: d, reason: collision with root package name */ private int f12144d; /* renamed from: e, reason: collision with root package name */ private boolean f12145e; /* renamed from: f, reason: collision with root package name */ final k.b f12146f; m(h5.e eVar, boolean z10) { this.f12141a = eVar; this.f12142b = z10; h5.d dVar = new h5.d(); this.f12143c = dVar; this.f12146f = new k.b(dVar); this.f12144d = 16384; } private static void S(h5.e eVar, int i10) { eVar.h((i10 >>> 16) & 255); eVar.h((i10 >>> 8) & 255); eVar.h(i10 & 255); } private void n0(int i10, long j10) { while (j10 > 0) { int min = (int) Math.min(this.f12144d, j10); long j11 = min; j10 -= j11; G(i10, min, (byte) 9, j10 == 0 ? (byte) 4 : (byte) 0); this.f12141a.k0(this.f12143c, j11); } } public void G(int i10, int i11, byte b10, byte b11) { Logger logger = f12140g; if (logger.isLoggable(Level.FINE)) { logger.fine(d.c(false, i10, i11, b10, b11)); } int i12 = this.f12144d; if (i11 > i12) { d.a("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(i12), Integer.valueOf(i11)); throw null; } if ((Integer.MIN_VALUE & i10) != 0) { d.a("reserved bit set: %s", Integer.valueOf(i10)); throw null; } S(this.f12141a, i11); this.f12141a.h(b10 & 255); this.f12141a.h(b11 & 255); this.f12141a.f(i10 & Api.BaseClientBuilder.API_PRIORITY_OTHER); } public synchronized void I(int i10, int i11, List list) { if (this.f12145e) { throw new IOException("closed"); } this.f12146f.e(list); long u02 = this.f12143c.u0(); int min = (int) Math.min(this.f12144d - 4, u02); long j10 = min; G(i10, min + 4, (byte) 5, u02 == j10 ? (byte) 4 : (byte) 0); this.f12141a.f(i11 & Api.BaseClientBuilder.API_PRIORITY_OTHER); this.f12141a.k0(this.f12143c, j10); if (u02 > j10) { n0(i10, u02 - j10); } } public synchronized void O(int i10, long j10) { if (this.f12145e) { throw new IOException("closed"); } if (j10 == 0 || j10 > 2147483647L) { d.a("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j10)); throw null; } G(i10, 4, (byte) 8, (byte) 0); this.f12141a.f((int) j10); this.f12141a.flush(); } public synchronized void P(int i10, b bVar) { if (this.f12145e) { throw new IOException("closed"); } if (bVar.f11985a == -1) { throw new IllegalArgumentException(); } G(i10, 4, (byte) 3, (byte) 0); this.f12141a.f(bVar.f11985a); this.f12141a.flush(); } public synchronized void R(int i10, b bVar, byte[] bArr) { if (this.f12145e) { throw new IOException("closed"); } if (bVar.f11985a == -1) { d.a("errorCode.httpCode == -1", new Object[0]); throw null; } G(0, bArr.length + 8, (byte) 7, (byte) 0); this.f12141a.f(i10); this.f12141a.f(bVar.f11985a); if (bArr.length > 0) { this.f12141a.q(bArr); } this.f12141a.flush(); } public synchronized void Y(i iVar) { if (this.f12145e) { throw new IOException("closed"); } this.f12144d = iVar.h(this.f12144d); if (iVar.e() != -1) { this.f12146f.h(iVar.e()); } G(0, 0, (byte) 4, (byte) 1); this.f12141a.flush(); } public synchronized void a0(boolean z10, int i10, int i11) { if (this.f12145e) { throw new IOException("closed"); } G(0, 8, (byte) 6, z10 ? (byte) 1 : (byte) 0); this.f12141a.f(i10); this.f12141a.f(i11); this.f12141a.flush(); } public synchronized void c() { if (this.f12145e) { throw new IOException("closed"); } if (this.f12142b) { Logger logger = f12140g; if (logger.isLoggable(Level.FINE)) { logger.fine(i5.c.r(">> CONNECTION %s", d.f11995a.j())); } this.f12141a.q(d.f11995a.s()); this.f12141a.flush(); } } @Override // java.io.Closeable, java.lang.AutoCloseable public synchronized void close() { this.f12145e = true; this.f12141a.close(); } public synchronized void d0(boolean z10, int i10, int i11, List list) { if (this.f12145e) { throw new IOException("closed"); } j0(z10, i10, list); } public synchronized void f0(boolean z10, int i10, h5.d dVar, int i11) { if (this.f12145e) { throw new IOException("closed"); } z(i10, z10 ? (byte) 1 : (byte) 0, dVar, i11); } public synchronized void flush() { if (this.f12145e) { throw new IOException("closed"); } this.f12141a.flush(); } void j0(boolean z10, int i10, List list) { if (this.f12145e) { throw new IOException("closed"); } this.f12146f.e(list); long u02 = this.f12143c.u0(); int min = (int) Math.min(this.f12144d, u02); long j10 = min; byte b10 = u02 == j10 ? (byte) 4 : (byte) 0; if (z10) { b10 = (byte) (b10 | 1); } G(i10, min, (byte) 1, b10); this.f12141a.k0(this.f12143c, j10); if (u02 > j10) { n0(i10, u02 - j10); } } public int m0() { return this.f12144d; } public synchronized void q0(i iVar) { if (this.f12145e) { throw new IOException("closed"); } int i10 = 0; G(0, iVar.i() * 6, (byte) 4, (byte) 0); while (i10 < 10) { if (iVar.j(i10)) { this.f12141a.e(i10 == 4 ? 3 : i10 == 7 ? 4 : i10); this.f12141a.f(iVar.a(i10)); } i10++; } this.f12141a.flush(); } void z(int i10, byte b10, h5.d dVar, int i11) { G(i10, i11, (byte) 0, b10); if (i11 > 0) { this.f12141a.k0(dVar, i11); } } }