package com.google.android.gms.internal.ads;

import android.net.Uri;
import android.util.Base64;
import androidx.annotation.Nullable;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

/* JADX INFO: loaded from: classes2.dex */
public final class tu1 extends qr1 {

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

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

    @Nullable
    private dy1 zza;

    @Nullable
    private byte[] zzb;

    @Override // com.google.android.gms.internal.ads.sv1
    public final long b(dy1 dy1Var) throws zzhc, zzat {
        l(dy1Var);
        this.zza = dy1Var;
        Uri uriNormalizeScheme = dy1Var.f10564a.normalizeScheme();
        String scheme = uriNormalizeScheme.getScheme();
        ih1.R0("data".equals(scheme), "Unsupported scheme: %s", scheme);
        String schemeSpecificPart = uriNormalizeScheme.getSchemeSpecificPart();
        String str = bb1.f9474a;
        String[] strArrSplit = schemeSpecificPart.split(",", -1);
        if (strArrSplit.length != 2) {
            throw zzat.zza("Unexpected URI format: ".concat(String.valueOf(uriNormalizeScheme)), null);
        }
        String str2 = strArrSplit[1];
        if (strArrSplit[0].contains(";base64")) {
            try {
                this.zzb = Base64.decode(str2, 0);
            } catch (IllegalArgumentException e10) {
                throw zzat.zza("Error while parsing Base64 encoded string: ".concat(String.valueOf(str2)), e10);
            }
        } else {
            this.zzb = URLDecoder.decode(str2, StandardCharsets.US_ASCII.name()).getBytes(StandardCharsets.UTF_8);
        }
        int length = this.zzb.length;
        long j10 = length;
        long j11 = dy1Var.f10566c;
        if (j11 > j10) {
            this.zzb = null;
            throw new zzhc(2008);
        }
        int i10 = (int) j11;
        this.f17006d = i10;
        int i11 = length - i10;
        this.f17007e = i11;
        long j12 = dy1Var.f10567d;
        if (j12 != -1) {
            this.f17007e = (int) Math.min(i11, j12);
        }
        m(dy1Var);
        return j12 != -1 ? j12 : this.f17007e;
    }

    @Override // com.google.android.gms.internal.ads.eh2
    public final int d(byte[] bArr, int i10, int i11) {
        if (i11 == 0) {
            return 0;
        }
        int i12 = this.f17007e;
        if (i12 == 0) {
            return -1;
        }
        int iMin = Math.min(i11, i12);
        byte[] bArr2 = this.zzb;
        String str = bb1.f9474a;
        System.arraycopy(bArr2, this.f17006d, bArr, i10, iMin);
        this.f17006d += iMin;
        this.f17007e -= iMin;
        n(iMin);
        return iMin;
    }

    @Override // com.google.android.gms.internal.ads.qr1, com.google.android.gms.internal.ads.sv1, com.google.android.gms.internal.ads.n72
    @Nullable
    public final Uri zzc() {
        dy1 dy1Var = this.zza;
        if (dy1Var != null) {
            return dy1Var.f10564a;
        }
        return null;
    }

    @Override // com.google.android.gms.internal.ads.sv1
    public final void zzd() {
        if (this.zzb != null) {
            this.zzb = null;
            o();
        }
        this.zza = null;
    }
}
