package g5;

import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.MessageDigest;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class o implements a5.h {

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

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

    @Nullable
    private volatile byte[] cacheKeyBytes;

    @Nullable
    private String safeStringUrl;

    @Nullable
    private URL safeUrl;

    @Nullable
    private final String stringUrl;

    @Nullable
    private final URL url;

    public o(URL url) {
        t tVar = p.f26214a;
        this.url = (URL) t5.n.checkNotNull(url);
        this.stringUrl = null;
        this.f26211b = (p) t5.n.checkNotNull(tVar);
    }

    public final String b() {
        if (TextUtils.isEmpty(this.safeStringUrl)) {
            String string = this.stringUrl;
            if (TextUtils.isEmpty(string)) {
                string = ((URL) t5.n.checkNotNull(this.url)).toString();
            }
            this.safeStringUrl = Uri.encode(string, "@#&=*+-_.,:!?()/~'%;$");
        }
        return this.safeStringUrl;
    }

    @Override // a5.h
    public boolean equals(Object obj) {
        if (!(obj instanceof o)) {
            return false;
        }
        o oVar = (o) obj;
        return getCacheKey().equals(oVar.getCacheKey()) && this.f26211b.equals(oVar.f26211b);
    }

    public String getCacheKey() {
        String str = this.stringUrl;
        return str != null ? str : ((URL) t5.n.checkNotNull(this.url)).toString();
    }

    public Map<String, String> getHeaders() {
        return this.f26211b.a();
    }

    @Override // a5.h
    public int hashCode() {
        if (this.f26212c == 0) {
            int iHashCode = getCacheKey().hashCode();
            this.f26212c = iHashCode;
            this.f26212c = this.f26211b.hashCode() + (iHashCode * 31);
        }
        return this.f26212c;
    }

    public String toString() {
        return getCacheKey();
    }

    public String toStringUrl() {
        return b();
    }

    public URL toURL() throws MalformedURLException {
        if (this.safeUrl == null) {
            this.safeUrl = new URL(b());
        }
        return this.safeUrl;
    }

    @Override // a5.h
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
        if (this.cacheKeyBytes == null) {
            this.cacheKeyBytes = getCacheKey().getBytes(a5.h.f376a);
        }
        messageDigest.update(this.cacheKeyBytes);
    }

    public o(String str) {
        t tVar = p.f26214a;
        this.url = null;
        this.stringUrl = t5.n.checkNotEmpty(str);
        this.f26211b = (p) t5.n.checkNotNull(tVar);
    }
}
