package x9; import java.io.File; import java.io.FileOutputStream; 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 n { /* renamed from: a, reason: collision with root package name */ static final Logger f15494a = Logger.getLogger(n.class.getName()); final class a implements u { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ w f15495a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ OutputStream f15496b; a(w wVar, OutputStream outputStream) { this.f15495a = wVar; this.f15496b = outputStream; } @Override // x9.u public w b() { return this.f15495a; } @Override // x9.u, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f15496b.close(); } @Override // x9.u, java.io.Flushable public void flush() { this.f15496b.flush(); } @Override // x9.u public void t0(x9.c cVar, long j10) { x.b(cVar.f15468b, 0L, j10); while (j10 > 0) { this.f15495a.f(); r rVar = cVar.f15467a; int min = (int) Math.min(j10, rVar.f15510c - rVar.f15509b); this.f15496b.write(rVar.f15508a, rVar.f15509b, min); int i10 = rVar.f15509b + min; rVar.f15509b = i10; long j11 = min; j10 -= j11; cVar.f15468b -= j11; if (i10 == rVar.f15510c) { cVar.f15467a = rVar.b(); s.a(rVar); } } } public String toString() { return "sink(" + this.f15496b + ")"; } } final class b implements v { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ w f15497a; /* renamed from: b, reason: collision with root package name */ final /* synthetic */ InputStream f15498b; b(w wVar, InputStream inputStream) { this.f15497a = wVar; this.f15498b = inputStream; } @Override // x9.v public w b() { return this.f15497a; } @Override // x9.v, java.io.Closeable, java.lang.AutoCloseable public void close() { this.f15498b.close(); } @Override // x9.v public long s0(x9.c cVar, long j10) { if (j10 < 0) { throw new IllegalArgumentException("byteCount < 0: " + j10); } if (j10 == 0) { return 0L; } try { this.f15497a.f(); r D0 = cVar.D0(1); int read = this.f15498b.read(D0.f15508a, D0.f15510c, (int) Math.min(j10, 8192 - D0.f15510c)); if (read == -1) { return -1L; } D0.f15510c += read; long j11 = read; cVar.f15468b += j11; return j11; } catch (AssertionError e10) { if (n.d(e10)) { throw new IOException(e10); } throw e10; } } public String toString() { return "source(" + this.f15498b + ")"; } } final class c extends x9.a { /* renamed from: k, reason: collision with root package name */ final /* synthetic */ Socket f15499k; c(Socket socket) { this.f15499k = socket; } @Override // x9.a protected IOException o(IOException iOException) { SocketTimeoutException socketTimeoutException = new SocketTimeoutException("timeout"); if (iOException != null) { socketTimeoutException.initCause(iOException); } return socketTimeoutException; } @Override // x9.a protected void t() { try { this.f15499k.close(); } catch (AssertionError e10) { if (!n.d(e10)) { throw e10; } n.f15494a.log(Level.WARNING, "Failed to close timed out socket " + this.f15499k, (Throwable) e10); } catch (Exception e11) { n.f15494a.log(Level.WARNING, "Failed to close timed out socket " + this.f15499k, (Throwable) e11); } } } public static u a(File file) { if (file != null) { return f(new FileOutputStream(file, true)); } throw new IllegalArgumentException("file == null"); } public static d b(u uVar) { return new p(uVar); } public static e c(v vVar) { return new q(vVar); } static boolean d(AssertionError assertionError) { return (assertionError.getCause() == null || assertionError.getMessage() == null || !assertionError.getMessage().contains("getsockname failed")) ? false : true; } public static u e(File file) { if (file != null) { return f(new FileOutputStream(file)); } throw new IllegalArgumentException("file == null"); } public static u f(OutputStream outputStream) { return g(outputStream, new w()); } private static u g(OutputStream outputStream, w wVar) { if (outputStream == null) { throw new IllegalArgumentException("out == null"); } if (wVar != null) { return new a(wVar, outputStream); } throw new IllegalArgumentException("timeout == null"); } public static u h(Socket socket) { if (socket == null) { throw new IllegalArgumentException("socket == null"); } if (socket.getOutputStream() == null) { throw new IOException("socket's output stream == null"); } x9.a l10 = l(socket); return l10.r(g(socket.getOutputStream(), l10)); } public static v i(InputStream inputStream) { return j(inputStream, new w()); } private static v j(InputStream inputStream, w wVar) { if (inputStream == null) { throw new IllegalArgumentException("in == null"); } if (wVar != null) { return new b(wVar, inputStream); } throw new IllegalArgumentException("timeout == null"); } public static v k(Socket socket) { if (socket == null) { throw new IllegalArgumentException("socket == null"); } if (socket.getInputStream() == null) { throw new IOException("socket's input stream == null"); } x9.a l10 = l(socket); return l10.s(j(socket.getInputStream(), l10)); } private static x9.a l(Socket socket) { return new c(socket); } }