package Nm6q_10;

import androidx.recyclerview.widget.RecyclerView;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
/* compiled from: RealBufferedSource.kt */
/* loaded from: classes.dex */
public final class Eps4cJe_18 implements IMuAHx_6 {
    public final G83uNX_24 KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final X6FRs_4 f323KQgRr5e_0;
    public boolean QxJ9d_1;

    public Eps4cJe_18(G83uNX_24 g83uNX_24) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(g83uNX_24, "source");
        this.KQgRr5e_0 = g83uNX_24;
        this.f323KQgRr5e_0 = new X6FRs_4();
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public X6FRs_4 KQgRr5e_0() {
        return this.f323KQgRr5e_0;
    }

    @Override // Nm6q_10.IMuAHx_6
    public void QxJ9d_1(long j) {
        if (!(!this.QxJ9d_1)) {
            throw new IllegalStateException("closed".toString());
        }
        while (j > 0) {
            if (this.f323KQgRr5e_0.PGPF6hQ_2() == 0 && this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                throw new EOFException();
            }
            long min = Math.min(j, this.f323KQgRr5e_0.PGPF6hQ_2());
            this.f323KQgRr5e_0.QxJ9d_1(min);
            j -= min;
        }
    }

    @Override // Nm6q_10.G83uNX_24, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public void close() {
        if (this.QxJ9d_1) {
            return;
        }
        this.QxJ9d_1 = true;
        this.KQgRr5e_0.close();
        this.f323KQgRr5e_0.KQgRr5e_0();
    }

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

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer byteBuffer) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(byteBuffer, "sink");
        if (this.f323KQgRr5e_0.PGPF6hQ_2() == 0 && this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
            return -1;
        }
        return this.f323KQgRr5e_0.read(byteBuffer);
    }

    @Override // Nm6q_10.IMuAHx_6
    public byte readByte() {
        KQgRr5e_0(1L);
        return this.f323KQgRr5e_0.readByte();
    }

    @Override // Nm6q_10.IMuAHx_6
    public void readFully(byte[] bArr) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bArr, "sink");
        try {
            KQgRr5e_0(bArr.length);
            this.f323KQgRr5e_0.readFully(bArr);
        } catch (EOFException e) {
            int i = 0;
            while (this.f323KQgRr5e_0.PGPF6hQ_2() > 0) {
                X6FRs_4 x6FRs_4 = this.f323KQgRr5e_0;
                int KQgRr5e_02 = x6FRs_4.KQgRr5e_0(bArr, i, (int) x6FRs_4.PGPF6hQ_2());
                if (KQgRr5e_02 == -1) {
                    throw new AssertionError();
                }
                i += KQgRr5e_02;
            }
            throw e;
        }
    }

    @Override // Nm6q_10.IMuAHx_6
    public int readInt() {
        KQgRr5e_0(4L);
        return this.f323KQgRr5e_0.readInt();
    }

    @Override // Nm6q_10.IMuAHx_6
    public short readShort() {
        KQgRr5e_0(2L);
        return this.f323KQgRr5e_0.readShort();
    }

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

    @Override // Nm6q_10.G83uNX_24
    public long KQgRr5e_0(X6FRs_4 x6FRs_4, long j) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(x6FRs_4, "sink");
        if (j >= 0) {
            if (true ^ this.QxJ9d_1) {
                if (this.f323KQgRr5e_0.PGPF6hQ_2() == 0 && this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                    return -1L;
                }
                return this.f323KQgRr5e_0.KQgRr5e_0(x6FRs_4, Math.min(j, this.f323KQgRr5e_0.PGPF6hQ_2()));
            }
            throw new IllegalStateException("closed".toString());
        }
        throw new IllegalArgumentException(("byteCount < 0: " + j).toString());
    }

    /* compiled from: RealBufferedSource.kt */
    /* loaded from: classes.dex */
    public static final class KQgRr5e_0 extends InputStream {
        public KQgRr5e_0() {
        }

        @Override // java.io.InputStream
        public int available() {
            Eps4cJe_18 eps4cJe_18 = Eps4cJe_18.this;
            if (!eps4cJe_18.QxJ9d_1) {
                return (int) Math.min(eps4cJe_18.f323KQgRr5e_0.PGPF6hQ_2(), Integer.MAX_VALUE);
            }
            throw new IOException("closed");
        }

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

        @Override // java.io.InputStream
        public int read() {
            Eps4cJe_18 eps4cJe_18 = Eps4cJe_18.this;
            if (!eps4cJe_18.QxJ9d_1) {
                if (eps4cJe_18.f323KQgRr5e_0.PGPF6hQ_2() == 0) {
                    Eps4cJe_18 eps4cJe_182 = Eps4cJe_18.this;
                    if (eps4cJe_182.KQgRr5e_0.KQgRr5e_0(eps4cJe_182.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                        return -1;
                    }
                }
                return Eps4cJe_18.this.f323KQgRr5e_0.readByte() & 255;
            }
            throw new IOException("closed");
        }

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

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i, int i2) {
            FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bArr, "data");
            if (!Eps4cJe_18.this.QxJ9d_1) {
                PGPF6hQ_2.KQgRr5e_0(bArr.length, i, i2);
                if (Eps4cJe_18.this.f323KQgRr5e_0.PGPF6hQ_2() == 0) {
                    Eps4cJe_18 eps4cJe_18 = Eps4cJe_18.this;
                    if (eps4cJe_18.KQgRr5e_0.KQgRr5e_0(eps4cJe_18.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                        return -1;
                    }
                }
                return Eps4cJe_18.this.f323KQgRr5e_0.KQgRr5e_0(bArr, i, i2);
            }
            throw new IOException("closed");
        }
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public boolean KQgRr5e_0() {
        if (!this.QxJ9d_1) {
            return this.f323KQgRr5e_0.KQgRr5e_0() && this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IMuAHx_6
    public void KQgRr5e_0(long j) {
        if (!KQgRr5e_0(j)) {
            throw new EOFException();
        }
    }

    @Override // Nm6q_10.IMuAHx_6
    public boolean KQgRr5e_0(long j) {
        if (j >= 0) {
            if (!this.QxJ9d_1) {
                while (this.f323KQgRr5e_0.PGPF6hQ_2() < j) {
                    if (this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                        return false;
                    }
                }
                return true;
            }
            throw new IllegalStateException("closed".toString());
        }
        throw new IllegalArgumentException(("byteCount < 0: " + j).toString());
    }

    @Override // Nm6q_10.IMuAHx_6
    public FSaI4_7 KQgRr5e_0(long j) {
        KQgRr5e_0(j);
        return this.f323KQgRr5e_0.KQgRr5e_0(j);
    }

    @Override // Nm6q_10.IMuAHx_6
    public byte[] KQgRr5e_0(long j) {
        KQgRr5e_0(j);
        return this.f323KQgRr5e_0.KQgRr5e_0(j);
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public String KQgRr5e_0() {
        return KQgRr5e_0(RecyclerView.FOREVER_NS);
    }

    @Override // Nm6q_10.IMuAHx_6
    public String KQgRr5e_0(long j) {
        if (j >= 0) {
            long j2 = j == RecyclerView.FOREVER_NS ? Long.MAX_VALUE : j + 1;
            byte b = (byte) 10;
            long KQgRr5e_02 = KQgRr5e_0(b, 0L, j2);
            if (KQgRr5e_02 != -1) {
                return this.f323KQgRr5e_0.PGPF6hQ_2(KQgRr5e_02);
            }
            if (j2 < RecyclerView.FOREVER_NS && KQgRr5e_0(j2) && this.f323KQgRr5e_0.KQgRr5e_0(j2 - 1) == ((byte) 13) && KQgRr5e_0(1 + j2) && this.f323KQgRr5e_0.KQgRr5e_0(j2) == b) {
                return this.f323KQgRr5e_0.PGPF6hQ_2(j2);
            }
            X6FRs_4 x6FRs_4 = new X6FRs_4();
            X6FRs_4 x6FRs_42 = this.f323KQgRr5e_0;
            x6FRs_42.KQgRr5e_0(x6FRs_4, 0L, Math.min(32, x6FRs_42.PGPF6hQ_2()));
            throw new EOFException("\\n not found: limit=" + Math.min(this.f323KQgRr5e_0.PGPF6hQ_2(), j) + " content=" + x6FRs_4.KQgRr5e_0().m164PGPF6hQ_2() + "…");
        }
        throw new IllegalArgumentException(("limit < 0: " + j).toString());
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public short KQgRr5e_0() {
        KQgRr5e_0(2L);
        return this.f323KQgRr5e_0.KQgRr5e_0();
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public int KQgRr5e_0() {
        KQgRr5e_0(4L);
        return this.f323KQgRr5e_0.KQgRr5e_0();
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public long KQgRr5e_0() {
        byte KQgRr5e_02;
        KQgRr5e_0(1L);
        int i = 0;
        while (true) {
            int i2 = i + 1;
            if (!KQgRr5e_0(i2)) {
                break;
            }
            KQgRr5e_02 = this.f323KQgRr5e_0.KQgRr5e_0(i);
            if ((KQgRr5e_02 < ((byte) 48) || KQgRr5e_02 > ((byte) 57)) && ((KQgRr5e_02 < ((byte) 97) || KQgRr5e_02 > ((byte) 102)) && (KQgRr5e_02 < ((byte) 65) || KQgRr5e_02 > ((byte) 70)))) {
                break;
            }
            i = i2;
        }
        if (i == 0) {
            FSaI4_7.Xgtqvk_8.QxJ9d_1.XnFJ5_9 xnFJ5_9 = FSaI4_7.Xgtqvk_8.QxJ9d_1.XnFJ5_9.KQgRr5e_0;
            String format = String.format("Expected leading [0-9a-fA-F] character but was %#x", Arrays.copyOf(new Object[]{Byte.valueOf(KQgRr5e_02)}, 1));
            FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0((Object) format, "java.lang.String.format(format, *args)");
            throw new NumberFormatException(format);
        }
        return this.f323KQgRr5e_0.KQgRr5e_0();
    }

    public long KQgRr5e_0(byte b) {
        return KQgRr5e_0(b, 0L, RecyclerView.FOREVER_NS);
    }

    public long KQgRr5e_0(byte b, long j, long j2) {
        boolean z = true;
        if (!this.QxJ9d_1) {
            if (!((0 > j || j2 < j) ? false : false)) {
                throw new IllegalArgumentException(("fromIndex=" + j + " toIndex=" + j2).toString());
            }
            while (j < j2) {
                long KQgRr5e_02 = this.f323KQgRr5e_0.KQgRr5e_0(b, j, j2);
                if (KQgRr5e_02 == -1) {
                    long PGPF6hQ_2 = this.f323KQgRr5e_0.PGPF6hQ_2();
                    if (PGPF6hQ_2 >= j2 || this.KQgRr5e_0.KQgRr5e_0(this.f323KQgRr5e_0, (long) RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST) == -1) {
                        break;
                    }
                    j = Math.max(j, PGPF6hQ_2);
                } else {
                    return KQgRr5e_02;
                }
            }
            return -1L;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public InputStream KQgRr5e_0() {
        return new KQgRr5e_0();
    }

    @Override // Nm6q_10.IMuAHx_6, Nm6q_10.G83uNX_24
    public KVtv3R_25 KQgRr5e_0() {
        return this.KQgRr5e_0.KQgRr5e_0();
    }
}
