package r4;

import com.google.protobuf.AbstractC1335v;
import com.google.protobuf.B0;
import com.google.protobuf.C1331t;
import com.google.protobuf.InterfaceC1332t0;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.logging.Logger;
import k4.M;

/* JADX INFO: renamed from: r4.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2888a extends InputStream implements M {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final B0 f23999b;

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

    public C2888a(InterfaceC1332t0 interfaceC1332t0, B0 b02) {
        this.f23998a = interfaceC1332t0;
        this.f23999b = b02;
    }

    @Override // java.io.InputStream
    public final int available() {
        InterfaceC1332t0 interfaceC1332t0 = this.f23998a;
        if (interfaceC1332t0 != null) {
            return interfaceC1332t0.getSerializedSize();
        }
        ByteArrayInputStream byteArrayInputStream = this.f24000c;
        if (byteArrayInputStream != null) {
            return byteArrayInputStream.available();
        }
        return 0;
    }

    @Override // java.io.InputStream
    public final int read() {
        if (this.f23998a != null) {
            this.f24000c = new ByteArrayInputStream(this.f23998a.toByteArray());
            this.f23998a = null;
        }
        ByteArrayInputStream byteArrayInputStream = this.f24000c;
        if (byteArrayInputStream != null) {
            return byteArrayInputStream.read();
        }
        return -1;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i6, int i7) {
        InterfaceC1332t0 interfaceC1332t0 = this.f23998a;
        if (interfaceC1332t0 != null) {
            int serializedSize = interfaceC1332t0.getSerializedSize();
            if (serializedSize == 0) {
                this.f23998a = null;
                this.f24000c = null;
                return -1;
            }
            if (i7 >= serializedSize) {
                Logger logger = AbstractC1335v.f14361d;
                C1331t c1331t = new C1331t(bArr, i6, serializedSize);
                this.f23998a.writeTo(c1331t);
                if (c1331t.b0() == 0) {
                    this.f23998a = null;
                    this.f24000c = null;
                    return serializedSize;
                }
                throw new IllegalStateException("Did not write as much data as expected.");
            }
            this.f24000c = new ByteArrayInputStream(this.f23998a.toByteArray());
            this.f23998a = null;
        }
        ByteArrayInputStream byteArrayInputStream = this.f24000c;
        if (byteArrayInputStream != null) {
            return byteArrayInputStream.read(bArr, i6, i7);
        }
        return -1;
    }
}
