package defpackage;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

/* renamed from: ᵛᵢᵔ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2753 implements InterfaceC4777 {

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C0963 f10636 = new C0963();

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final InterfaceC3226 f10637;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public boolean f10638;

    public C2753(InterfaceC3226 interfaceC3226) {
        this.f10637 = interfaceC3226;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public final void close() throws IOException {
        if (this.f10638) {
            return;
        }
        this.f10638 = true;
        this.f10637.close();
        this.f10636.m3277();
    }

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

    @Override // java.nio.channels.ReadableByteChannel
    public final int read(ByteBuffer byteBuffer) {
        C0963 c0963 = this.f10636;
        if (c0963.f4314 == 0 && this.f10637.mo2229(c0963, 8192L) == -1) {
            return -1;
        }
        return c0963.read(byteBuffer);
    }

    @Override // defpackage.InterfaceC4777
    public final byte readByte() throws EOFException {
        mo3256(1L);
        return this.f10636.readByte();
    }

    @Override // defpackage.InterfaceC4777
    public final int readInt() throws EOFException {
        mo3256(4L);
        return this.f10636.readInt();
    }

    @Override // defpackage.InterfaceC4777
    public final short readShort() throws EOFException {
        mo3256(2L);
        return this.f10636.readShort();
    }

    @Override // defpackage.InterfaceC4777
    public final boolean request(long j) {
        C0963 c0963;
        if (j < 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC4737.m10015(j, "byteCount < 0: "));
            return false;
        }
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return false;
        }
        do {
            c0963 = this.f10636;
            if (c0963.f4314 >= j) {
                return true;
            }
        } while (this.f10637.mo2229(c0963, 8192L) != -1);
        return false;
    }

    @Override // defpackage.InterfaceC4777
    public final void skip(long j) throws EOFException {
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return;
        }
        while (j > 0) {
            C0963 c0963 = this.f10636;
            if (c0963.f4314 == 0 && this.f10637.mo2229(c0963, 8192L) == -1) {
                throw new EOFException();
            }
            long jMin = Math.min(j, c0963.f4314);
            c0963.skip(jMin);
            j -= jMin;
        }
    }

    public final String toString() {
        return "buffer(" + this.f10637 + ')';
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ˀˁᵨ */
    public final void mo3256(long j) throws EOFException {
        if (!request(j)) {
            throw new EOFException();
        }
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final long m6788() throws EOFException {
        char c;
        char c2;
        char c3;
        char c4;
        long j;
        mo3256(8L);
        C0963 c0963 = this.f10636;
        long j2 = c0963.f4314;
        if (j2 < 8) {
            throw new EOFException();
        }
        C3514 c3514 = c0963.f4315;
        int i = c3514.f13190;
        int i2 = c3514.f13188;
        if (i2 - i < 8) {
            j = ((c0963.readInt() & 4294967295L) << 32) | (4294967295L & c0963.readInt());
            c2 = '8';
            c = 24;
            c4 = '\b';
            c3 = '(';
        } else {
            byte[] bArr = c3514.f13189;
            c = 24;
            c2 = '8';
            c3 = '(';
            c4 = '\b';
            int i3 = i + 7;
            long j3 = ((bArr[i] & 255) << 56) | ((bArr[i + 1] & 255) << 48) | ((bArr[i + 2] & 255) << 40) | ((bArr[i + 3] & 255) << 32) | ((bArr[i + 4] & 255) << 24) | ((bArr[i + 5] & 255) << 16) | ((bArr[i + 6] & 255) << 8);
            int i4 = i + 8;
            j = j3 | (bArr[i3] & 255);
            c0963.f4314 = j2 - 8;
            if (i4 == i2) {
                c0963.f4315 = c3514.m8039();
                AbstractC3467.m7895(c3514);
            } else {
                c3514.f13190 = i4;
            }
        }
        return ((j & 255) << c2) | (((-72057594037927936L) & j) >>> c2) | ((71776119061217280L & j) >>> c3) | ((280375465082880L & j) >>> c) | ((1095216660480L & j) >>> c4) | ((4278190080L & j) << c4) | ((16711680 & j) << c) | ((65280 & j) << c3);
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ˌᵪ */
    public final long mo3262(C2185 c2185) {
        return ᵸᵡˋʧ.ᵻᵢﹳᵰ(this, c2185, c2185.mo5840(), Long.MAX_VALUE);
    }

    @Override // defpackage.InterfaceC4777, defpackage.InterfaceC3656
    /* renamed from: ˎˏʜʾ */
    public final C0963 mo3263() {
        return this.f10636;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final int m6789() throws EOFException {
        mo3256(4L);
        int i = this.f10636.readInt();
        return ((i & 255) << 24) | (((-16777216) & i) >>> 24) | ((16711680 & i) >>> 8) | ((65280 & i) << 8);
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ˑᵝﹳᵜ */
    public final boolean mo3266(C2185 c2185) {
        int iMo5840 = c2185.mo5840();
        if (!this.f10638) {
            return iMo5840 >= 0 && iMo5840 <= c2185.mo5840() && (iMo5840 == 0 || ᵸᵡˋʧ.ᵻᵢﹳᵰ(this, c2185, iMo5840, 1L) != -1);
        }
        ᵹˉᵞ.ᵳٴᵶ("closed");
        return false;
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ˑᵱ */
    public final int mo3268(C2679 c2679) throws EOFException {
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return 0;
        }
        while (true) {
            C0963 c0963 = this.f10636;
            int iM9871 = AbstractC4683.m9871(c0963, c2679, true);
            if (iM9871 != -2) {
                if (iM9871 != -1) {
                    c0963.skip(c2679.f10405[iM9871].mo5840());
                    return iM9871;
                }
            } else if (this.f10637.mo2229(c0963, 8192L) == -1) {
                break;
            }
        }
        return -1;
    }

    @Override // defpackage.InterfaceC3226
    /* renamed from: ᵝᵵᵺ */
    public final C3948 mo2227() {
        return this.f10637.mo2227();
    }

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public final short m6790() throws EOFException {
        mo3256(2L);
        return this.f10636.m3265();
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵠᵿː */
    public final InputStream mo3271() {
        return new C4402(2, this);
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵡʠ */
    public final C2185 mo3272(long j) throws EOFException {
        mo3256(j);
        return this.f10636.mo3272(j);
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵡᵶᵡ */
    public final long mo3275(C0963 c0963) {
        C0963 c09632;
        long j = 0;
        while (true) {
            InterfaceC3226 interfaceC3226 = this.f10637;
            c09632 = this.f10636;
            if (interfaceC3226.mo2229(c09632, 8192L) == -1) {
                break;
            }
            long jM3276 = c09632.m3276();
            if (jM3276 > 0) {
                j += jM3276;
                c0963.mo2377(c09632, jM3276);
            }
        }
        long j2 = c09632.f4314;
        if (j2 <= 0) {
            return j;
        }
        long j3 = j + j2;
        c0963.mo2377(c09632, j2);
        return j3;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final long m6791(byte b, long j, long j2) {
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return 0L;
        }
        if (0 > j2) {
            ᵹˉᵞ.ᵸˑ(AbstractC4737.m10015(j2, "fromIndex=0 toIndex="));
            return 0L;
        }
        long jMax = 0;
        while (jMax < j2) {
            C0963 c0963 = this.f10636;
            byte b2 = b;
            long j3 = j2;
            long jM3261 = c0963.m3261(b2, jMax, j3);
            if (jM3261 != -1) {
                return jM3261;
            }
            long j4 = c0963.f4314;
            if (j4 >= j3 || this.f10637.mo2229(c0963, 8192L) == -1) {
                break;
            }
            jMax = Math.max(jMax, j4);
            b = b2;
            j2 = j3;
        }
        return -1L;
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵧـˌᵎ */
    public final long mo3281(C2185 c2185) {
        long jMax = 0;
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return 0L;
        }
        while (true) {
            C0963 c0963 = this.f10636;
            long jM3257 = c0963.m3257(c2185, jMax);
            if (jM3257 != -1) {
                return jM3257;
            }
            long j = c0963.f4314;
            if (this.f10637.mo2229(c0963, 8192L) == -1) {
                return -1L;
            }
            jMax = Math.max(jMax, j);
        }
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵧᵾˀˈ */
    public final String mo3282() {
        long jM6791 = m6791((byte) 10, 0L, Long.MAX_VALUE);
        C0963 c0963 = this.f10636;
        if (jM6791 != -1) {
            return AbstractC4683.m9868(c0963, jM6791);
        }
        long j = c0963.f4314;
        if (j != 0) {
            return mo3285(j);
        }
        return null;
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵨᵳʝ */
    public final boolean mo3284() {
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return false;
        }
        C0963 c0963 = this.f10636;
        return c0963.mo3284() && this.f10637.mo2229(c0963, 8192L) == -1;
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵪʩ */
    public final String mo3285(long j) throws EOFException {
        mo3256(j);
        return this.f10636.m3292(j, AbstractC2356.f9221);
    }

    @Override // defpackage.InterfaceC3226
    /* renamed from: ᵳٴᵶ */
    public final long mo2229(C0963 c0963, long j) {
        if (j < 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC4737.m10015(j, "byteCount < 0: "));
            return 0L;
        }
        if (this.f10638) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return 0L;
        }
        C0963 c09632 = this.f10636;
        if (c09632.f4314 == 0) {
            if (j == 0) {
                return 0L;
            }
            if (this.f10637.mo2229(c09632, 8192L) == -1) {
                return -1L;
            }
        }
        return c09632.mo2229(c0963, Math.min(j, c09632.f4314));
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵶʔᵢˊ */
    public final String mo3291(Charset charset) {
        InterfaceC3226 interfaceC3226 = this.f10637;
        C0963 c0963 = this.f10636;
        c0963.m3295(interfaceC3226);
        return c0963.m3292(c0963.f4314, charset);
    }

    @Override // defpackage.InterfaceC4777
    /* renamed from: ᵾᵬ */
    public final String mo3294(long j) throws EOFException {
        if (j < 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC4737.m10015(j, "limit < 0: "));
            return null;
        }
        long j2 = j == Long.MAX_VALUE ? Long.MAX_VALUE : j + 1;
        long jM6791 = m6791((byte) 10, 0L, j2);
        C0963 c0963 = this.f10636;
        if (jM6791 != -1) {
            return AbstractC4683.m9868(c0963, jM6791);
        }
        if (j2 < Long.MAX_VALUE && request(j2) && c0963.m3267(j2 - 1) == 13 && request(j2 + 1) && c0963.m3267(j2) == 10) {
            return AbstractC4683.m9868(c0963, j2);
        }
        C0963 c09632 = new C0963();
        c0963.m3273(c09632, 0L, Math.min(32L, c0963.f4314));
        throw new EOFException("\\n not found: limit=" + Math.min(c0963.f4314, j) + " content=" + c09632.mo3272(c09632.f4314).mo5850() + (char) 8230);
    }
}
