笔 趣 阁 破 解 版2023 v4.18.00版本的 MD5 值为:35c48a89f5572ff5a659afd7c5a81cad

以下内容为反编译后的 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 {
    public m akF;
    public HttpURLConnection akG;
    public InputStream akH;
    public final com.kwad.sdk.core.videocache.c.b akj;
    public 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 i) {
        long c2 = c(httpURLConnection);
        return i == 200 ? c2 : i == 206 ? c2 + 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 i) {
        String str;
        HttpURLConnection httpURLConnection;
        boolean z;
        String str2 = this.akF.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.b.d("HttpUrlSource", sb.toString());
            httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
            q.wrapHttpURLConnection(httpURLConnection);
            a(httpURLConnection, str2);
            if (i3 > 0) {
                httpURLConnection.setRequestProperty("Range", "bytes=" + j + "-");
            }
            if (i > 0) {
                httpURLConnection.setConnectTimeout(i);
                httpURLConnection.setReadTimeout(i);
            }
            o.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;
    }

    public 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 c2 = c(httpURLConnection);
                    String contentType = httpURLConnection.getContentType();
                    inputStream = httpURLConnection.getInputStream();
                    m mVar = new m(this.akF.url, c2, 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 b2 = b(j, -1);
            this.akG = b2;
            String contentType = b2.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 e) {
            throw new ProxyCacheException("Error opening connection for " + this.akF.url + " with offset " + j, e);
        }
    }

    @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 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 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 e) {
            throw new InterruptedProxyCacheException("Reading source " + this.akF.url + " is interrupted", e);
        } catch (IOException e2) {
            throw new ProxyCacheException("Error reading data from " + this.akF.url, e2);
        }
    }

    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;
    }
}