package o;

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

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.m00, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1822m00 implements InterfaceC1687kf {
    public final T90 l;
    public final C0732af m = new C0732af();
    public boolean n;

    public C1822m00(T90 t90) {
        this.l = t90;
    }

    @Override // o.InterfaceC1687kf
    public final String A(long j) throws EOFException {
        if (j < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.l("limit < 0: ", j).toString());
        }
        long j2 = j == Long.MAX_VALUE ? Long.MAX_VALUE : j + 1;
        long jC = c((byte) 10, 0L, j2);
        C0732af c0732af = this.m;
        if (jC != -1) {
            return AbstractC0771b.a(jC, c0732af);
        }
        if (j2 < Long.MAX_VALUE && n(j2) && c0732af.g(j2 - 1) == 13 && n(j2 + 1) && c0732af.g(j2) == 10) {
            return AbstractC0771b.a(j2, c0732af);
        }
        C0732af c0732af2 = new C0732af();
        c0732af.d(c0732af2, 0L, Math.min(32, c0732af.m));
        throw new EOFException("\\n not found: limit=" + Math.min(c0732af.m, j) + " content=" + c0732af2.i(c0732af2.m).c() + (char) 8230);
    }

    @Override // o.T90
    public final long C(long j, C0732af c0732af) {
        if (j < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.l("byteCount < 0: ", j).toString());
        }
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        C0732af c0732af2 = this.m;
        if (c0732af2.m == 0 && this.l.C(8192L, c0732af2) == -1) {
            return -1L;
        }
        return c0732af2.C(Math.min(j, c0732af2.m), c0732af);
    }

    @Override // o.InterfaceC1687kf
    public final long H(C1632k00 c1632k00) {
        C0732af c0732af;
        long j = 0;
        while (true) {
            T90 t90 = this.l;
            c0732af = this.m;
            if (t90.C(8192L, c0732af) == -1) {
                break;
            }
            long jC = c0732af.c();
            if (jC > 0) {
                j += jC;
                c1632k00.e(jC, c0732af);
            }
        }
        long j2 = c0732af.m;
        if (j2 <= 0) {
            return j;
        }
        long j3 = j + j2;
        c1632k00.e(j2, c0732af);
        return j3;
    }

    @Override // o.InterfaceC1687kf
    public final void I(long j) throws EOFException {
        if (!n(j)) {
            throw new EOFException();
        }
    }

    @Override // o.InterfaceC1687kf
    public final long O() throws EOFException {
        C0732af c0732af;
        byte bG;
        I(1L);
        int i = 0;
        while (true) {
            int i2 = i + 1;
            boolean zN = n(i2);
            c0732af = this.m;
            if (!zN) {
                break;
            }
            bG = c0732af.g(i);
            if ((bG < 48 || bG > 57) && ((bG < 97 || bG > 102) && (bG < 65 || bG > 70))) {
                break;
            }
            i = i2;
        }
        if (i == 0) {
            AbstractC0940cn0.g(16);
            AbstractC0940cn0.g(16);
            throw new NumberFormatException("Expected leading [0-9a-fA-F] character but was 0x".concat(Integer.toString(bG, 16)));
        }
        return c0732af.O();
    }

    @Override // o.InterfaceC1687kf
    public final int P(MU mu) {
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        while (true) {
            C0732af c0732af = this.m;
            int iB = AbstractC0771b.b(c0732af, mu, true);
            if (iB != -2) {
                if (iB != -1) {
                    c0732af.skip(mu.l[iB].b());
                    return iB;
                }
            } else if (this.l.C(8192L, c0732af) == -1) {
                break;
            }
        }
        return -1;
    }

    @Override // o.InterfaceC1687kf
    public final String Q(Charset charset) {
        T90 t90 = this.l;
        C0732af c0732af = this.m;
        c0732af.N(t90);
        return c0732af.u(c0732af.m, charset);
    }

    @Override // o.T90
    public final Cf0 a() {
        return this.l.a();
    }

    public final boolean b() {
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        C0732af c0732af = this.m;
        return c0732af.f() && this.l.C(8192L, c0732af) == -1;
    }

    public final long c(byte b, long j, long j2) {
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        if (0 > j2) {
            throw new IllegalArgumentException(AbstractC0126Ew.l("fromIndex=0 toIndex=", j2).toString());
        }
        long jMax = 0;
        while (jMax < j2) {
            C0732af c0732af = this.m;
            byte b2 = b;
            long j3 = j2;
            long j4 = c0732af.j(b2, jMax, j3);
            if (j4 != -1) {
                return j4;
            }
            long j5 = c0732af.m;
            if (j5 >= j3 || this.l.C(8192L, c0732af) == -1) {
                break;
            }
            jMax = Math.max(jMax, j5);
            b = b2;
            j2 = j3;
        }
        return -1L;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public final void close() throws IOException {
        if (this.n) {
            return;
        }
        this.n = true;
        this.l.close();
        this.m.b();
    }

    public final long d() throws EOFException {
        char c;
        char c2;
        char c3;
        char c4;
        long j;
        I(8L);
        C0732af c0732af = this.m;
        long j2 = c0732af.m;
        if (j2 < 8) {
            throw new EOFException();
        }
        C2496t50 c2496t50 = c0732af.l;
        int i = c2496t50.b;
        int i2 = c2496t50.c;
        if (i2 - i < 8) {
            j = ((c0732af.readInt() & 4294967295L) << 32) | (4294967295L & c0732af.readInt());
            c2 = '8';
            c4 = '\b';
            c3 = '(';
            c = 24;
        } else {
            byte[] bArr = c2496t50.a;
            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;
            long j4 = j3 | (bArr[i3] & 255);
            c0732af.m = j2 - 8;
            if (i4 == i2) {
                c0732af.l = c2496t50.a();
                AbstractC2781w50.a(c2496t50);
            } else {
                c2496t50.b = i4;
            }
            j = j4;
        }
        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);
    }

    public final String f(long j) {
        I(j);
        C0732af c0732af = this.m;
        c0732af.getClass();
        return c0732af.u(j, AbstractC2355rh.a);
    }

    @Override // o.InterfaceC1687kf
    public final C0135Ff i(long j) throws EOFException {
        I(j);
        return this.m.i(j);
    }

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

    @Override // o.InterfaceC1687kf
    public final boolean n(long j) {
        C0732af c0732af;
        if (j < 0) {
            throw new IllegalArgumentException(AbstractC0126Ew.l("byteCount < 0: ", j).toString());
        }
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        do {
            c0732af = this.m;
            if (c0732af.m >= j) {
                return true;
            }
        } while (this.l.C(8192L, c0732af) != -1);
        return false;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public final int read(ByteBuffer byteBuffer) {
        C0732af c0732af = this.m;
        if (c0732af.m == 0 && this.l.C(8192L, c0732af) == -1) {
            return -1;
        }
        return c0732af.read(byteBuffer);
    }

    @Override // o.InterfaceC1687kf
    public final byte readByte() throws EOFException {
        I(1L);
        return this.m.readByte();
    }

    @Override // o.InterfaceC1687kf
    public final int readInt() throws EOFException {
        I(4L);
        return this.m.readInt();
    }

    @Override // o.InterfaceC1687kf
    public final short readShort() throws EOFException {
        I(2L);
        return this.m.readShort();
    }

    @Override // o.InterfaceC1687kf
    public final String s() {
        return A(Long.MAX_VALUE);
    }

    @Override // o.InterfaceC1687kf
    public final void skip(long j) {
        if (this.n) {
            throw new IllegalStateException("closed");
        }
        while (j > 0) {
            C0732af c0732af = this.m;
            if (c0732af.m == 0 && this.l.C(8192L, c0732af) == -1) {
                throw new EOFException();
            }
            long jMin = Math.min(j, c0732af.m);
            c0732af.skip(jMin);
            j -= jMin;
        }
    }

    @Override // o.InterfaceC1687kf
    public final int t() {
        I(4L);
        return this.m.t();
    }

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

    @Override // o.InterfaceC1687kf
    public final C0732af v() {
        return this.m;
    }

    @Override // o.InterfaceC1687kf
    public final short x() {
        I(2L);
        return this.m.x();
    }
}
