package defpackage;

import androidx.media3.container.NalUnitUtil;
import java.io.IOException;
import java.io.InputStream;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0012\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lhn4;", "Lss7;", "kotlinx-io-core"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
class hn4 implements ss7 {
    public final InputStream a;

    public hn4(InputStream inputStream) {
        cr4.g(inputStream, "input");
        this.a = inputStream;
    }

    @Override // java.lang.AutoCloseable
    public final void close() throws IOException {
        this.a.close();
    }

    @Override // defpackage.ss7
    public final long s(mg0 mg0Var, long j) throws IOException {
        cr4.g(mg0Var, "sink");
        if (j == 0) {
            return 0L;
        }
        if (j < 0) {
            throw new IllegalArgumentException(fi7.e(j, "byteCount (", ") < 0").toString());
        }
        boolean z = false;
        try {
            le8 le8VarK = mg0Var.k(1);
            long j2 = this.a.read(le8VarK.a, le8VarK.c, (int) Math.min(j, r4.length - r5));
            int i = j2 == -1 ? 0 : (int) j2;
            if (i == 1) {
                le8VarK.c += i;
                mg0Var.c += (long) i;
                return j2;
            }
            if (i < 0 || i > le8VarK.a()) {
                throw new IllegalStateException(("Invalid number of bytes written: " + i + ". Should be in 0.." + le8VarK.a()).toString());
            }
            if (i != 0) {
                le8VarK.c += i;
                mg0Var.c += (long) i;
                return j2;
            }
            if (qe8.a(le8VarK)) {
                mg0Var.d();
            }
            return j2;
        } catch (AssertionError e) {
            if (e.getCause() != null) {
                String message = e.getMessage();
                if (message != null ? n89.l(message, "getsockname failed", false) : false) {
                    z = true;
                }
            }
            if (z) {
                throw new IOException(e);
            }
            throw e;
        }
    }

    public final String toString() {
        return "RawSource(" + this.a + ')';
    }
}
