package h5; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.net.SocketTimeoutException; import java.util.logging.Level; import java.util.logging.Logger; /* loaded from: classes2.dex */ public abstract class g0 { /* renamed from: a, reason: collision with root package name */ static final Logger f10077a = Logger.getLogger(g0.class.getName()); class a implements n0 { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ p0 f10078a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ OutputStream f10079b; a(p0 p0Var, OutputStream outputStream) { this.f10078a = p0Var; this.f10079b = outputStream; } @Override // h5.n0 public p0 b() { return this.f10078a; } @Override // h5.n0, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f10079b.close(); } @Override // h5.n0, java.io.Flushable public void flush() { this.f10079b.flush(); } @Override // h5.n0 public void k0(d dVar, long j10) { y0.c(dVar.f10014b, 0L, j10); while (j10 > 0) { this.f10078a.f(); v0 v0Var = dVar.f10013a; int min = (int) Math.min(j10, v0Var.f10311c - v0Var.f10310b); this.f10079b.write(v0Var.f10309a, v0Var.f10310b, min); int i10 = v0Var.f10310b + min; v0Var.f10310b = i10; long j11 = min; j10 -= j11; dVar.f10014b -= j11; if (i10 == v0Var.f10311c) { dVar.f10013a = v0Var.e(); w0.b(v0Var); } } } public String toString() { return "sink(" + this.f10079b + ")"; } } class b implements o0 { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ p0 f10080a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ InputStream f10081b; b(p0 p0Var, InputStream inputStream) { this.f10080a = p0Var; this.f10081b = inputStream; } @Override // h5.o0 public long H(d dVar, long j10) { if (j10 < 0) { throw new IllegalArgumentException("byteCount < 0: " + j10); } if (j10 == 0) { return 0L; } try { this.f10080a.f(); v0 I = dVar.I(1); int read = this.f10081b.read(I.f10309a, I.f10311c, (int) Math.min(j10, 8192 - I.f10311c)); if (read == -1) { return -1L; } I.f10311c += read; long j11 = read; dVar.f10014b += j11; return j11; } catch (AssertionError e10) { if (g0.d(e10)) { throw new IOException(e10); } throw e10; } } @Override // h5.o0 public p0 b() { return this.f10080a; } @Override // h5.o0, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f10081b.close(); } public String toString() { return "source(" + this.f10081b + ")"; } } class c extends h5.b { /* renamed from: k, reason: collision with root package name */ final /* synthetic */ Socket f10082k; c(Socket socket) { this.f10082k = socket; } @Override // h5.b protected IOException o(IOException iOException) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (iOException != null) { socketTimeoutException.initCause(iOException); } return socketTimeoutException; } /* JADX WARN: Multi-variable type inference failed */ @Override // h5.b protected void p() { Level level; StringBuilder sb; Logger logger; Exception exc; try { this.f10082k.close(); } catch (AssertionError e10) { if (!g0.d(e10)) { throw e10; } Logger logger2 = g0.f10077a; level = Level.WARNING; sb = new StringBuilder(); exc = e10; logger = logger2; sb.append("Failed to close timed out socket "); sb.append(this.f10082k); logger.log(level, sb.toString(), (Throwable) exc); } catch (Exception e11) { Logger logger3 = g0.f10077a; level = Level.WARNING; sb = new StringBuilder(); exc = e11; logger = logger3; sb.append("Failed to close timed out socket "); sb.append(this.f10082k); logger.log(level, sb.toString(), (Throwable) exc); } } } private static h5.b a(Socket socket) { return new c(socket); } private static n0 b(OutputStream outputStream, p0 p0Var) { if (outputStream == null) { throw new IllegalArgumentException("out == null"); } if (p0Var != null) { return new a(p0Var, outputStream); } throw new IllegalArgumentException("timeout == null"); } private static o0 c(InputStream inputStream, p0 p0Var) { if (inputStream == null) { throw new IllegalArgumentException("in == null"); } if (p0Var != null) { return new b(p0Var, inputStream); } throw new IllegalArgumentException("timeout == null"); } static boolean d(AssertionError assertionError) { return (assertionError.getCause() == null || assertionError.toString() == null || !assertionError.toString().contains("getsockname failed")) ? false : true; } public static e e(n0 n0Var) { return new s0(n0Var); } public static f f(o0 o0Var) { return new t0(o0Var); } public static n0 g(Socket socket) { if (socket == null) { throw new IllegalArgumentException("socket == null"); } if (socket.getOutputStream() == null) { throw new IOException("socket's output stream == null"); } h5.b a10 = a(socket); return a10.s(b(socket.getOutputStream(), a10)); } public static o0 h(InputStream inputStream) { return c(inputStream, new p0()); } public static o0 i(Socket socket) { if (socket == null) { throw new IllegalArgumentException("socket == null"); } if (socket.getInputStream() == null) { throw new IOException("socket's input stream == null"); } h5.b a10 = a(socket); return a10.t(c(socket.getInputStream(), a10)); } }