我要上王者 v1.1版本的 MD5 值为:b7d3566522def961cabeb92cb17f5db9

以下内容为反编译后的 h.java 源代码,内容仅作参考


package com.kwad.sdk.core.videocache;

import android.text.TextUtils;
import com.kwad.sdk.core.network.r;
import com.kwad.sdk.utils.ap;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.apache.commons.cli.HelpFormatter;
public final class h extends p {
    private n aAm;
    private HttpURLConnection aAn;
    private InputStream aAo;
    private final com.kwad.sdk.core.videocache.d.c azO;
    private final com.kwad.sdk.core.videocache.b.b azP;

    public h(String str, com.kwad.sdk.core.videocache.d.c cVar, com.kwad.sdk.core.videocache.b.b bVar) {
        this.azO = (com.kwad.sdk.core.videocache.d.c) ap.checkNotNull(cVar);
        this.azP = (com.kwad.sdk.core.videocache.b.b) ap.checkNotNull(bVar);
        n ed = cVar.ed(str);
        this.aAm = ed == null ? new n(str, -2147483648L, l.eb(str)) : ed;
    }

    public h(h hVar) {
        this.aAm = hVar.aAm;
        this.azO = hVar.azO;
        this.azP = hVar.azP;
    }

    @Override
    public final synchronized long length() {
        if (this.aAm.aAC == -2147483648L) {
            EQ();
        }
        if (this.aAm.aAC == -2147483648L) {
            EO();
        }
        return this.aAm.aAC;
    }

    @Override
    public final void al(long j) {
        try {
            HttpURLConnection c = c(j, -1);
            this.aAn = c;
            String contentType = c.getContentType();
            this.aAo = new BufferedInputStream(this.aAn.getInputStream(), 1024);
            HttpURLConnection httpURLConnection = this.aAn;
            n nVar = new n(this.aAm.url, a(httpURLConnection, j, httpURLConnection.getResponseCode()), contentType);
            this.aAm = nVar;
            this.azO.a(nVar.url, this.aAm);
        } catch (IOException e) {
            throw new ProxyCacheException("Error opening connection for " + this.aAm.url + " with offset " + j, e);
        }
    }

    private long a(HttpURLConnection httpURLConnection, long j, int i) {
        long d = d(httpURLConnection);
        return i == 200 ? d : i == 206 ? d + j : this.aAm.aAC;
    }

    private static long d(HttpURLConnection httpURLConnection) {
        String headerField = httpURLConnection.getHeaderField("Content-Length");
        if (headerField == null) {
            return -1L;
        }
        return Long.parseLong(headerField);
    }

    @Override
    public final void close() {
        HttpURLConnection httpURLConnection = this.aAn;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException unused) {
                com.kwad.sdk.core.e.c.e("HttpUrlSource", "Error closing connection correctly. Should happen only on Android L. If anybody know how to fix it, please visit https://github.com/danikula/AndroidVideoCache/issues/88. Until good solution is not know, just ignore this issue.");
            } catch (IllegalArgumentException e) {
                e = e;
                throw new RuntimeException("Wait... but why? WTF!? Really shouldn't happen any more after fixing https://github.com/danikula/AndroidVideoCache/issues/43. If you read it on your device log, please, notify me danikula@gmail.com or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
            } catch (NullPointerException e2) {
                e = e2;
                throw new RuntimeException("Wait... but why? WTF!? Really shouldn't happen any more after fixing https://github.com/danikula/AndroidVideoCache/issues/43. If you read it on your device log, please, notify me danikula@gmail.com or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
            }
        }
    }

    @Override
    public final int read(byte[] bArr) {
        InputStream inputStream = this.aAo;
        if (inputStream == null) {
            throw new ProxyCacheException("Error reading data from " + this.aAm.url + ": connection is absent!");
        }
        try {
            return inputStream.read(bArr, 0, 1024);
        } catch (InterruptedIOException e) {
            throw new InterruptedProxyCacheException("Reading source " + this.aAm.url + " is interrupted", e);
        } catch (IOException e2) {
            throw new ProxyCacheException("Error reading data from " + this.aAm.url, e2);
        }
    }

    private void EO() {
        HttpURLConnection httpURLConnection;
        com.kwad.sdk.core.e.c.d("HttpUrlSource", "Read content info from " + this.aAm.url);
        ?? r0 = 10000;
        InputStream inputStream = null;
        try {
            try {
                httpURLConnection = c(0L, 10000);
                try {
                    long d = d(httpURLConnection);
                    String contentType = httpURLConnection.getContentType();
                    inputStream = httpURLConnection.getInputStream();
                    n nVar = new n(this.aAm.url, d, contentType);
                    this.aAm = nVar;
                    this.azO.a(nVar.url, this.aAm);
                    com.kwad.sdk.core.e.c.d("HttpUrlSource", "Source info fetched: " + this.aAm);
                    r0 = httpURLConnection;
                } catch (IOException unused) {
                    com.kwad.sdk.core.e.c.e("HttpUrlSource", "Error fetching info from " + this.aAm.url);
                    r0 = httpURLConnection;
                    com.kwad.sdk.crash.utils.b.closeQuietly(inputStream);
                    com.kwad.sdk.crash.utils.b.a(r0);
                }
            } catch (Throwable th) {
                th = th;
                com.kwad.sdk.crash.utils.b.closeQuietly(inputStream);
                com.kwad.sdk.crash.utils.b.a(r0);
                throw th;
            }
        } catch (IOException unused2) {
            httpURLConnection = null;
        } catch (Throwable th2) {
            th = th2;
            r0 = 0;
            com.kwad.sdk.crash.utils.b.closeQuietly(inputStream);
            com.kwad.sdk.crash.utils.b.a(r0);
            throw th;
        }
        com.kwad.sdk.crash.utils.b.closeQuietly(inputStream);
        com.kwad.sdk.crash.utils.b.a(r0);
    }

    private HttpURLConnection c(long j, int i) {
        String str;
        HttpURLConnection httpURLConnection;
        boolean z;
        String str2 = this.aAm.url;
        int i2 = 0;
        do {
            StringBuilder sb = new StringBuilder("Open connection ");
            int i3 = (j > 0L ? 1 : (j == 0L ? 0 : -1));
            if (i3 > 0) {
                str = " with offset " + j;
            } else {
                str = "";
            }
            sb.append(str);
            sb.append(" to ");
            sb.append(str2);
            com.kwad.sdk.core.e.c.d("HttpUrlSource", sb.toString());
            httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
            r.wrapHttpURLConnection(httpURLConnection);
            a(httpURLConnection, str2);
            if (i3 > 0) {
                httpURLConnection.setRequestProperty("Range", "bytes=" + j + HelpFormatter.DEFAULT_OPT_PREFIX);
            }
            if (i > 0) {
                httpURLConnection.setConnectTimeout(i);
                httpURLConnection.setReadTimeout(i);
            }
            com.kwad.sdk.core.network.p.b(httpURLConnection);
            int responseCode = httpURLConnection.getResponseCode();
            z = responseCode == 301 || responseCode == 302 || responseCode == 303;
            if (z) {
                str2 = httpURLConnection.getHeaderField("Location");
                i2++;
                httpURLConnection.disconnect();
            }
            if (i2 > 5) {
                throw new ProxyCacheException("Too many redirects: " + i2);
            }
        } while (z);
        return httpURLConnection;
    }

    private void a(HttpURLConnection httpURLConnection, String str) {
        for (Map.Entry<String, String> entry : this.azP.EX().entrySet()) {
            httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
        }
    }

    @Override
    public final synchronized String EP() {
        if (TextUtils.isEmpty(this.aAm.aAD)) {
            EQ();
        }
        if (TextUtils.isEmpty(this.aAm.aAD)) {
            EO();
        }
        return this.aAm.aAD;
    }

    @Override
    public final String getUrl() {
        return this.aAm.url;
    }

    private void EQ() {
        n ed;
        com.kwad.sdk.core.videocache.d.c cVar = this.azO;
        if (cVar == null || !(cVar instanceof com.kwad.sdk.core.videocache.d.b) || (ed = cVar.ed(getUrl())) == null || TextUtils.isEmpty(ed.aAD) || ed.aAC == -2147483648L) {
            return;
        }
        this.aAm = ed;
    }

    @Override
    public final String toString() {
        return "HttpUrlSource{sourceInfo='" + this.aAm + "}";
    }
}