花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e

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


package com.kwad.sdk.core.videocache;

import android.text.TextUtils;
import com.kwad.sdk.core.network.o;
import com.kwad.sdk.core.network.q;
import com.kwad.sdk.utils.an;
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;
public final class h implements l {
    private m akF;
    private HttpURLConnection akG;
    private InputStream akH;
    private final com.kwad.sdk.core.videocache.c.b akj;
    private final com.kwad.sdk.core.videocache.a.b akk;

    public h(h hVar) {
        this.akF = hVar.akF;
        this.akj = hVar.akj;
        this.akk = hVar.akk;
    }

    public h(String str, com.kwad.sdk.core.videocache.c.b bVar, com.kwad.sdk.core.videocache.a.b bVar2) {
        this.akj = (com.kwad.sdk.core.videocache.c.b) an.checkNotNull(bVar);
        this.akk = (com.kwad.sdk.core.videocache.a.b) an.checkNotNull(bVar2);
        m cU = bVar.cU(str);
        this.akF = cU == null ? new m(str, -2147483648L, k.cS(str)) : cU;
    }

    private long a(HttpURLConnection httpURLConnection, long j, int i2) {
        long c = c(httpURLConnection);
        return i2 == 200 ? c : i2 == 206 ? c + j : this.akF.akU;
    }

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

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

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

    private void xZ() {
        HttpURLConnection httpURLConnection;
        com.kwad.sdk.core.e.b.d("HttpUrlSource", "Read content info from " + this.akF.url);
        ?? r0 = 10000;
        InputStream inputStream = null;
        try {
            try {
                httpURLConnection = b(0L, 10000);
                try {
                    long c = c(httpURLConnection);
                    String contentType = httpURLConnection.getContentType();
                    inputStream = httpURLConnection.getInputStream();
                    m mVar = new m(this.akF.url, c, contentType);
                    this.akF = mVar;
                    this.akj.a(mVar.url, mVar);
                    com.kwad.sdk.core.e.b.d("HttpUrlSource", "Source info fetched: " + this.akF);
                    r0 = httpURLConnection;
                } catch (IOException unused) {
                    com.kwad.sdk.core.e.b.e("HttpUrlSource", "Error fetching info from " + this.akF.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);
    }

    @Override
    public final void T(long j) {
        try {
            HttpURLConnection b = b(j, -1);
            this.akG = b;
            String contentType = b.getContentType();
            this.akH = new BufferedInputStream(this.akG.getInputStream(), 8192);
            m mVar = new m(this.akF.url, a(this.akG, j, this.akG.getResponseCode()), contentType);
            this.akF = mVar;
            this.akj.a(mVar.url, mVar);
        } catch (IOException e2) {
            throw new ProxyCacheException("Error opening connection for " + this.akF.url + " with offset " + j, e2);
        }
    }

    @Override
    public final void close() {
        HttpURLConnection httpURLConnection = this.akG;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException unused) {
                com.kwad.sdk.core.e.b.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 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);
            } catch (NullPointerException e3) {
                e = e3;
                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 synchronized long length() {
        if (this.akF.akU == -2147483648L) {
            xZ();
        }
        return this.akF.akU;
    }

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

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

    public final synchronized String ya() {
        if (TextUtils.isEmpty(this.akF.akV)) {
            xZ();
        }
        return this.akF.akV;
    }
}