package h;

import java.io.IOException;

/* JADX INFO: loaded from: classes.dex */
public class a implements w {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ w f6515b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ c f6516c;

    public a(c cVar, w wVar) {
        this.f6516c = cVar;
        this.f6515b = wVar;
    }

    @Override // h.w, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.f6516c.i();
        try {
            try {
                this.f6515b.close();
                this.f6516c.j(true);
            } catch (IOException e2) {
                c cVar = this.f6516c;
                if (!cVar.k()) {
                    throw e2;
                }
                throw cVar.l(e2);
            }
        } catch (Throwable th) {
            this.f6516c.j(false);
            throw th;
        }
    }

    @Override // h.w
    public y e() {
        return this.f6516c;
    }

    @Override // h.w, java.io.Flushable
    public void flush() throws IOException {
        this.f6516c.i();
        try {
            try {
                this.f6515b.flush();
                this.f6516c.j(true);
            } catch (IOException e2) {
                c cVar = this.f6516c;
                if (!cVar.k()) {
                    throw e2;
                }
                throw cVar.l(e2);
            }
        } catch (Throwable th) {
            this.f6516c.j(false);
            throw th;
        }
    }

    @Override // h.w
    public void h(f fVar, long j2) throws IOException {
        z.b(fVar.f6529d, 0L, j2);
        while (true) {
            long j3 = 0;
            if (j2 <= 0) {
                return;
            }
            t tVar = fVar.f6528c;
            while (true) {
                if (j3 >= 65536) {
                    break;
                }
                j3 += (long) (tVar.f6562c - tVar.f6561b);
                if (j3 >= j2) {
                    j3 = j2;
                    break;
                }
                tVar = tVar.f6565f;
            }
            this.f6516c.i();
            try {
                try {
                    this.f6515b.h(fVar, j3);
                    j2 -= j3;
                    this.f6516c.j(true);
                } catch (IOException e2) {
                    c cVar = this.f6516c;
                    if (!cVar.k()) {
                        throw e2;
                    }
                    throw cVar.l(e2);
                }
            } catch (Throwable th) {
                this.f6516c.j(false);
                throw th;
            }
        }
    }

    public String toString() {
        StringBuilder sbC = a.b.c.a.a.C("AsyncTimeout.sink(");
        sbC.append(this.f6515b);
        sbC.append(")");
        return sbC.toString();
    }
}
