package com.facetec.sdk; import com.facetec.sdk.lq; import com.google.common.primitives.UnsignedBytes; import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes.dex */ public final class lz implements Closeable { private static final Logger c = Logger.getLogger(lt.class.getName()); private final mv a; private final ms b; private final boolean d; int e; private lq.c g; private boolean i; /* JADX INFO: Access modifiers changed from: package-private */ public lz(mv mvVar, boolean z) { this.a = mvVar; this.d = z; ms msVar = new ms(); this.b = msVar; this.g = new lq.c(msVar); this.e = 16384; } public final void e() throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } if (this.d) { Logger logger = c; if (logger.isLoggable(Level.FINE)) { logger.fine(km.a(">> CONNECTION %s", lt.d.c())); } this.a.e(lt.d.g()); this.a.flush(); } } } public final void c() throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } this.a.flush(); } } public final void e(int i, lo loVar) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } if (loVar.f == -1) { throw new IllegalArgumentException(); } d(i, 4, (byte) 3, (byte) 0); this.a.f(loVar.f); this.a.flush(); } } public final void b(boolean z, int i, int i2) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } d(0, 8, (byte) 6, z ? (byte) 1 : (byte) 0); this.a.f(i); this.a.f(i2); this.a.flush(); } } public final void c(int i, lo loVar, byte[] bArr) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } if (loVar.f == -1) { throw lt.e("errorCode.httpCode == -1", new Object[0]); } d(0, bArr.length + 8, (byte) 7, (byte) 0); this.a.f(i); this.a.f(loVar.f); if (bArr.length > 0) { this.a.e(bArr); } this.a.flush(); } } public final void c(int i, long j) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } if (j == 0 || j > 2147483647L) { throw lt.e("windowSizeIncrement == 0 || windowSizeIncrement > 0x7fffffffL: %s", Long.valueOf(j)); } d(i, 4, (byte) 8, (byte) 0); this.a.f((int) j); this.a.flush(); } } private void d(int i, int i2, byte b, byte b2) throws IOException { Logger logger = c; if (logger.isLoggable(Level.FINE)) { logger.fine(lt.e(false, i, i2, b, b2)); } int i3 = this.e; if (i2 > i3) { throw lt.e("FRAME_SIZE_ERROR length > %d: %d", Integer.valueOf(i3), Integer.valueOf(i2)); } if ((Integer.MIN_VALUE & i) != 0) { throw lt.e("reserved bit set: %s", Integer.valueOf(i)); } b(this.a, i2); this.a.h(b & UnsignedBytes.MAX_VALUE); this.a.h(b2 & UnsignedBytes.MAX_VALUE); this.a.f(i & Integer.MAX_VALUE); } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { synchronized (this) { this.i = true; this.a.close(); } } private static void b(mv mvVar, int i) throws IOException { mvVar.h((i >>> 16) & 255); mvVar.h((i >>> 8) & 255); mvVar.h(i & 255); } public final void d(mb mbVar) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } int i = this.e; if ((mbVar.e & 32) != 0) { i = mbVar.a[5]; } this.e = i; if (mbVar.d() != -1) { lq.c cVar = this.g; int d = mbVar.d(); cVar.e = d; int min = Math.min(d, 16384); if (cVar.c != min) { if (min < cVar.c) { cVar.b = Math.min(cVar.b, min); } cVar.d = true; cVar.c = min; if (cVar.c < cVar.h) { if (cVar.c == 0) { cVar.d(); } else { cVar.b(cVar.h - cVar.c); } } } } d(0, 0, (byte) 4, (byte) 1); this.a.flush(); } } public final void d(boolean z, int i, List list) throws IOException { int i2; int i3; synchronized (this) { boolean z2 = this.i; if (z2) { throw new IOException("closed"); } if (z2) { throw new IOException("closed"); } lq.c cVar = this.g; if (cVar.d) { if (cVar.b < cVar.c) { cVar.a(cVar.b, 31, 32); } cVar.d = false; cVar.b = Integer.MAX_VALUE; cVar.a(cVar.c, 31, 32); } int size = list.size(); for (int i4 = 0; i4 < size; i4++) { ln lnVar = list.get(i4); mt f = lnVar.h.f(); mt mtVar = lnVar.j; Integer num = lq.c.get(f); if (num != null) { int intValue = num.intValue(); i3 = intValue + 1; if (i3 > 1 && i3 < 8) { if (km.b(lq.a[intValue].j, mtVar)) { i2 = i3; } else if (km.b(lq.a[i3].j, mtVar)) { i2 = intValue + 2; } } i2 = -1; } else { i2 = -1; i3 = -1; } if (i2 == -1) { int i5 = cVar.i + 1; int length = cVar.f.length; while (true) { if (i5 >= length) { break; } if (km.b(cVar.f[i5].h, f)) { if (km.b(cVar.f[i5].j, mtVar)) { i2 = (i5 - cVar.i) + lq.a.length; break; } else if (i3 == -1) { i3 = (i5 - cVar.i) + lq.a.length; } } i5++; } } if (i2 != -1) { cVar.a(i2, 127, 128); } else if (i3 == -1) { cVar.a.h(64); cVar.d(f); cVar.d(mtVar); cVar.c(lnVar); } else if (f.e(ln.d) && !ln.i.equals(f)) { cVar.a(i3, 15, 0); cVar.d(mtVar); } else { cVar.a(i3, 63, 64); cVar.d(mtVar); cVar.c(lnVar); } } long c2 = this.b.c(); int min = (int) Math.min(this.e, c2); long j = min; byte b = c2 == j ? (byte) 4 : (byte) 0; if (z) { b = (byte) (b | 1); } d(i, min, (byte) 1, b); this.a.c(this.b, j); if (c2 > j) { long j2 = c2 - j; while (j2 > 0) { int min2 = (int) Math.min(this.e, j2); long j3 = min2; j2 -= j3; d(i, min2, (byte) 9, j2 == 0 ? (byte) 4 : (byte) 0); this.a.c(this.b, j3); } } } } public final void b(boolean z, int i, ms msVar, int i2) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } d(i, i2, (byte) 0, z ? (byte) 1 : (byte) 0); if (i2 > 0) { this.a.c(msVar, i2); } } } public final void c(mb mbVar) throws IOException { synchronized (this) { if (this.i) { throw new IOException("closed"); } int i = 0; d(0, Integer.bitCount(mbVar.e) * 6, (byte) 4, (byte) 0); while (i < 10) { if (mbVar.e(i)) { this.a.g(i == 4 ? 3 : i == 7 ? 4 : i); this.a.f(mbVar.b(i)); } i++; } this.a.flush(); } } }