package com.google.protobuf;

import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;

/* JADX INFO: renamed from: com.google.protobuf.c0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C1299c0 extends InputStream {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Iterator f14241a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ByteBuffer f14242b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f14243c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f14244d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f14245e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f14246f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public byte[] f14247j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f14248k;
    public long l;

    public final boolean a() {
        this.f14244d++;
        Iterator it = this.f14241a;
        if (!it.hasNext()) {
            return false;
        }
        ByteBuffer byteBuffer = (ByteBuffer) it.next();
        this.f14242b = byteBuffer;
        this.f14245e = byteBuffer.position();
        if (this.f14242b.hasArray()) {
            this.f14246f = true;
            this.f14247j = this.f14242b.array();
            this.f14248k = this.f14242b.arrayOffset();
            return true;
        }
        this.f14246f = false;
        this.l = c1.f14251c.j(c1.f14255g, this.f14242b);
        this.f14247j = null;
        return true;
    }

    public final void b(int i6) {
        int i7 = this.f14245e + i6;
        this.f14245e = i7;
        if (i7 == this.f14242b.limit()) {
            a();
        }
    }

    @Override // java.io.InputStream
    public final int read() {
        if (this.f14244d == this.f14243c) {
            return -1;
        }
        if (this.f14246f) {
            int i6 = this.f14247j[this.f14245e + this.f14248k] & 255;
            b(1);
            return i6;
        }
        int iE = c1.f14251c.e(((long) this.f14245e) + this.l) & 255;
        b(1);
        return iE;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i6, int i7) {
        if (this.f14244d == this.f14243c) {
            return -1;
        }
        int iLimit = this.f14242b.limit();
        int i8 = this.f14245e;
        int i9 = iLimit - i8;
        if (i7 > i9) {
            i7 = i9;
        }
        if (this.f14246f) {
            System.arraycopy(this.f14247j, i8 + this.f14248k, bArr, i6, i7);
            b(i7);
            return i7;
        }
        int iPosition = this.f14242b.position();
        this.f14242b.position(this.f14245e);
        this.f14242b.get(bArr, i6, i7);
        this.f14242b.position(iPosition);
        b(i7);
        return i7;
    }
}
