package p461;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;
import p461.p462.C7133;

/* JADX INFO: renamed from: ޑ.ޏ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7121 implements InterfaceC7107 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C7103 f20661;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public boolean f20662;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final InterfaceC7129 f20663;

    /* JADX INFO: renamed from: ޑ.ޏ$֏, reason: contains not printable characters */
    public static final class C7122 extends InputStream {
        public C7122() {
        }

        @Override // java.io.InputStream
        public int available() throws IOException {
            C7121 c7121 = C7121.this;
            if (c7121.f20662) {
                throw new IOException("closed");
            }
            return (int) Math.min(c7121.f20661.f20630, Integer.MAX_VALUE);
        }

        @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
        public void close() throws EOFException {
            C7121.this.close();
        }

        @Override // java.io.InputStream
        public int read() throws IOException {
            C7121 c7121 = C7121.this;
            if (c7121.f20662) {
                throw new IOException("closed");
            }
            C7103 c7103 = c7121.f20661;
            if (c7103.f20630 == 0 && c7121.f20663.mo10207(c7103, 8192) == -1) {
                return -1;
            }
            return C7121.this.f20661.readByte() & 255;
        }

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i, int i2) throws IOException {
            if (bArr == null) {
                C6635.m9824("data");
                throw null;
            }
            if (C7121.this.f20662) {
                throw new IOException("closed");
            }
            C4303.m7086(bArr.length, i, i2);
            C7121 c7121 = C7121.this;
            C7103 c7103 = c7121.f20661;
            if (c7103.f20630 == 0 && c7121.f20663.mo10207(c7103, 8192) == -1) {
                return -1;
            }
            return C7121.this.f20661.m10405(bArr, i, i2);
        }

        public String toString() {
            return C7121.this + ".inputStream()";
        }
    }

    public C7121(InterfaceC7129 interfaceC7129) {
        if (interfaceC7129 == null) {
            C6635.m9824("source");
            throw null;
        }
        this.f20663 = interfaceC7129;
        this.f20661 = new C7103();
    }

    @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws EOFException {
        if (this.f20662) {
            return;
        }
        this.f20662 = true;
        this.f20663.close();
        C7103 c7103 = this.f20661;
        c7103.skip(c7103.f20630);
    }

    @Override // p461.InterfaceC7107, p461.InterfaceC7106
    public C7103 getBuffer() {
        return this.f20661;
    }

    @Override // java.nio.channels.Channel
    public boolean isOpen() {
        return !this.f20662;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer byteBuffer) {
        if (byteBuffer == null) {
            C6635.m9824("sink");
            throw null;
        }
        C7103 c7103 = this.f20661;
        if (c7103.f20630 == 0 && this.f20663.mo10207(c7103, 8192) == -1) {
            return -1;
        }
        return this.f20661.read(byteBuffer);
    }

    @Override // p461.InterfaceC7107
    public byte readByte() throws EOFException {
        mo10431(1L);
        return this.f20661.readByte();
    }

    @Override // p461.InterfaceC7107
    public int readInt() throws EOFException {
        mo10431(4L);
        return this.f20661.readInt();
    }

    @Override // p461.InterfaceC7107
    public short readShort() throws EOFException {
        mo10431(2L);
        return this.f20661.readShort();
    }

    @Override // p461.InterfaceC7107
    public void skip(long j) throws EOFException {
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        while (j > 0) {
            C7103 c7103 = this.f20661;
            if (c7103.f20630 == 0 && this.f20663.mo10207(c7103, 8192) == -1) {
                throw new EOFException();
            }
            long jMin = Math.min(j, this.f20661.f20630);
            this.f20661.skip(jMin);
            j -= jMin;
        }
    }

    public String toString() {
        StringBuilder sbM4889 = C2803.m4889("buffer(");
        sbM4889.append(this.f20663);
        sbM4889.append(')');
        return sbM4889.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int m10472() throws EOFException {
        mo10431(4L);
        int i = this.f20661.readInt();
        return ((i & 255) << 24) | (((-16777216) & i) >>> 24) | ((16711680 & i) >>> 8) | ((65280 & i) << 8);
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public int mo10404(C7116 c7116) throws EOFException {
        if (c7116 == null) {
            C6635.m9824("options");
            throw null;
        }
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        while (true) {
            int iM10483 = C7133.m10483(this.f20661, c7116, true);
            if (iM10483 != -2) {
                if (iM10483 != -1) {
                    this.f20661.skip(c7116.f20653[iM10483].mo10450());
                    return iM10483;
                }
            } else if (this.f20663.mo10207(this.f20661, 8192) == -1) {
                break;
            }
        }
        return -1;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public long m10473(byte b) {
        return m10474(b, 0L, Long.MAX_VALUE);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public long m10474(byte b, long j, long j2) {
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        if (!(0 <= j && j2 >= j)) {
            throw new IllegalArgumentException(("fromIndex=" + j + " toIndex=" + j2).toString());
        }
        while (j < j2) {
            long jM10406 = this.f20661.m10406(b, j, j2);
            if (jM10406 != -1) {
                return jM10406;
            }
            C7103 c7103 = this.f20661;
            long j3 = c7103.f20630;
            if (j3 >= j2 || this.f20663.mo10207(c7103, 8192) == -1) {
                return -1L;
            }
            j = Math.max(j, j3);
        }
        return -1L;
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public long mo10407(C7108 c7108) {
        if (c7108 == null) {
            C6635.m9824("bytes");
            throw null;
        }
        long jMax = 0;
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        while (true) {
            long jM10408 = this.f20661.m10408(c7108, jMax);
            if (jM10408 != -1) {
                return jM10408;
            }
            C7103 c7103 = this.f20661;
            long j = c7103.f20630;
            if (this.f20663.mo10207(c7103, 8192) == -1) {
                return -1L;
            }
            jMax = Math.max(jMax, (j - ((long) c7108.mo10450())) + 1);
        }
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public long mo10409(InterfaceC7127 interfaceC7127) {
        if (interfaceC7127 == null) {
            C6635.m9824("sink");
            throw null;
        }
        long j = 0;
        while (this.f20663.mo10207(this.f20661, 8192) != -1) {
            long jM10419 = this.f20661.m10419();
            if (jM10419 > 0) {
                j += jM10419;
                interfaceC7127.mo10205(this.f20661, jM10419);
            }
        }
        C7103 c7103 = this.f20661;
        long j2 = c7103.f20630;
        if (j2 <= 0) {
            return j;
        }
        long j3 = j + j2;
        interfaceC7127.mo10205(c7103, j2);
        return j3;
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public String mo10411(long j) throws EOFException {
        if (mo10428(j)) {
            return this.f20661.mo10411(j);
        }
        throw new EOFException();
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public String mo10413(Charset charset) {
        if (charset == null) {
            C6635.m9824("charset");
            throw null;
        }
        this.f20661.mo10410(this.f20663);
        C7103 c7103 = this.f20661;
        return c7103.m10412(c7103.f20630, charset);
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ֏ */
    public boolean mo10418(long j, C7108 c7108) {
        if (c7108 == null) {
            C6635.m9824("bytes");
            throw null;
        }
        int iMo10450 = c7108.mo10450();
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        if (j >= 0 && iMo10450 >= 0 && c7108.mo10450() - 0 >= iMo10450) {
            for (int i = 0; i < iMo10450; i++) {
                long j2 = ((long) i) + j;
                if (mo10428(1 + j2) && this.f20661.m10433(j2) == c7108.mo10443(0 + i)) {
                }
            }
            return true;
        }
        return false;
    }

    @Override // p461.InterfaceC7129
    /* JADX INFO: renamed from: ؠ */
    public long mo10207(C7103 c7103, long j) {
        if (c7103 == null) {
            C6635.m9824("sink");
            throw null;
        }
        if (!(j >= 0)) {
            throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
        }
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        C7103 c71032 = this.f20661;
        if (c71032.f20630 == 0 && this.f20663.mo10207(c71032, 8192) == -1) {
            return -1L;
        }
        return this.f20661.mo10207(c7103, Math.min(j, this.f20661.f20630));
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ހ */
    public long mo10424(C7108 c7108) {
        if (c7108 == null) {
            C6635.m9824("targetBytes");
            throw null;
        }
        long jMax = 0;
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        while (true) {
            long jM10420 = this.f20661.m10420(c7108, jMax);
            if (jM10420 != -1) {
                return jM10420;
            }
            C7103 c7103 = this.f20661;
            long j = c7103.f20630;
            if (this.f20663.mo10207(c7103, 8192) == -1) {
                return -1L;
            }
            jMax = Math.max(jMax, j);
        }
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ހ */
    public C7108 mo10427(long j) throws EOFException {
        if (mo10428(j)) {
            return this.f20661.mo10427(j);
        }
        throw new EOFException();
    }

    @Override // p461.InterfaceC7129
    /* JADX INFO: renamed from: ށ */
    public C7130 mo10277() {
        return this.f20663.mo10277();
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ށ */
    public boolean mo10428(long j) {
        C7103 c7103;
        if (!(j >= 0)) {
            throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
        }
        if (!(!this.f20662)) {
            throw new IllegalStateException("closed".toString());
        }
        do {
            c7103 = this.f20661;
            if (c7103.f20630 >= j) {
                return true;
            }
        } while (this.f20663.mo10207(c7103, 8192) != -1);
        return false;
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ނ */
    public byte[] mo10429(long j) throws EOFException {
        if (mo10428(j)) {
            return this.f20661.mo10429(j);
        }
        throw new EOFException();
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ރ */
    public String mo10430(long j) throws EOFException {
        if (!(j >= 0)) {
            throw new IllegalArgumentException(C2803.m4874("limit < 0: ", j).toString());
        }
        long j2 = j == Long.MAX_VALUE ? Long.MAX_VALUE : j + 1;
        byte b = (byte) 10;
        long jM10474 = m10474(b, 0L, j2);
        if (jM10474 != -1) {
            return C7133.m10484(this.f20661, jM10474);
        }
        if (j2 < Long.MAX_VALUE && mo10428(j2) && this.f20661.m10433(j2 - 1) == ((byte) 13) && mo10428(1 + j2) && this.f20661.m10433(j2) == b) {
            return C7133.m10484(this.f20661, j2);
        }
        C7103 c7103 = new C7103();
        C7103 c71032 = this.f20661;
        c71032.m10416(c7103, 0L, Math.min(32, c71032.f20630));
        throw new EOFException("\\n not found: limit=" + Math.min(this.f20661.f20630, j) + " content=" + c7103.m10426().mo10451() + "…");
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ބ */
    public void mo10431(long j) throws EOFException {
        if (!mo10428(j)) {
            throw new EOFException();
        }
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: އ */
    public String mo10435() {
        return mo10430(Long.MAX_VALUE);
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ވ */
    public boolean mo10436() {
        if (!this.f20662) {
            return this.f20661.mo10436() && this.f20663.mo10207(this.f20661, (long) 8192) == -1;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ތ */
    public String mo10438() throws EOFException {
        long jM10473 = m10473((byte) 10);
        if (jM10473 != -1) {
            return C7133.m10484(this.f20661, jM10473);
        }
        long j = this.f20661.f20630;
        if (j == 0) {
            return null;
        }
        if (mo10428(j)) {
            return this.f20661.mo10411(j);
        }
        throw new EOFException();
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ޏ */
    public long mo10440() throws EOFException {
        byte bM10433;
        mo10431(1L);
        int i = 0;
        while (true) {
            int i2 = i + 1;
            if (!mo10428(i2)) {
                break;
            }
            bM10433 = this.f20661.m10433(i);
            if ((bM10433 < ((byte) 48) || bM10433 > ((byte) 57)) && ((bM10433 < ((byte) 97) || bM10433 > ((byte) 102)) && (bM10433 < ((byte) 65) || bM10433 > ((byte) 70)))) {
                break;
            }
            i = i2;
        }
        if (i == 0) {
            StringBuilder sb = new StringBuilder();
            sb.append("Expected leading [0-9a-fA-F] character but was 0x");
            C4303.m6976(16);
            C4303.m6976(16);
            String string = Integer.toString(bM10433, 16);
            C6635.m9823((Object) string, "java.lang.Integer.toStri…(this, checkRadix(radix))");
            sb.append(string);
            throw new NumberFormatException(sb.toString());
        }
        return this.f20661.mo10440();
    }

    @Override // p461.InterfaceC7107
    /* JADX INFO: renamed from: ޑ */
    public InputStream mo10441() {
        return new C7122();
    }
}
