CAG v5.7.4版本的 MD5 值为:bc57ead76a7a30559f0708e9d60d749f

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


package i.f.a;

import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import androidx.recyclerview.widget.RecyclerView;
import com.danikula.videocache.InterruptedProxyCacheException;
import com.danikula.videocache.ProxyCacheException;
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 java.util.Objects;
public class h implements m {
    public static final d.i.b f9932f = d.i.c.c("HttpUrlSource");
    public final i.f.a.r.c a;
    public final i.f.a.q.b b;
    public n c;
    public HttpURLConnection f9933d;
    public InputStream f9934e;

    public h(String str, i.f.a.r.c cVar, i.f.a.q.b bVar) {
        Objects.requireNonNull(cVar);
        this.a = cVar;
        Objects.requireNonNull(bVar);
        this.b = bVar;
        n c = cVar.c(str);
        if (c == null) {
            d.i.b bVar2 = l.a;
            MimeTypeMap singleton = MimeTypeMap.getSingleton();
            String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str);
            c = new n(str, -2147483648L, TextUtils.isEmpty(fileExtensionFromUrl) ? null : singleton.getMimeTypeFromExtension(fileExtensionFromUrl));
        }
        this.c = c;
    }

    @Override
    public void a(long j2) throws ProxyCacheException {
        try {
            HttpURLConnection c = c(j2, -1);
            this.f9933d = c;
            String contentType = c.getContentType();
            this.f9934e = new BufferedInputStream(this.f9933d.getInputStream(), RecyclerView.b0.FLAG_BOUNCED_FROM_HIDDEN_LIST);
            HttpURLConnection httpURLConnection = this.f9933d;
            int responseCode = httpURLConnection.getResponseCode();
            String headerField = httpURLConnection.getHeaderField("Content-Length");
            long parseLong = headerField == null ? -1L : Long.parseLong(headerField);
            if (responseCode != 200) {
                parseLong = responseCode == 206 ? parseLong + j2 : this.c.b;
            }
            String str = this.c.a;
            n nVar = new n(str, parseLong, contentType);
            this.c = nVar;
            this.a.d(str, nVar);
        } catch (IOException e2) {
            StringBuilder J = i.a.b.a.a.J("Error opening connection for ");
            J.append(this.c.a);
            J.append(" with offset ");
            J.append(j2);
            throw new ProxyCacheException(J.toString(), e2);
        }
    }

    public final void b() throws ProxyCacheException {
        HttpURLConnection httpURLConnection;
        d.i.b bVar = f9932f;
        StringBuilder J = i.a.b.a.a.J("Read content info from ");
        J.append(this.c.a);
        bVar.debug(J.toString());
        ?? r1 = 0;
        InputStream inputStream = null;
        try {
            try {
                httpURLConnection = c(0L, 10000);
                try {
                    String headerField = httpURLConnection.getHeaderField("Content-Length");
                    long parseLong = headerField == null ? -1L : Long.parseLong(headerField);
                    String contentType = httpURLConnection.getContentType();
                    inputStream = httpURLConnection.getInputStream();
                    String str = this.c.a;
                    n nVar = new n(str, parseLong, contentType);
                    this.c = nVar;
                    this.a.d(str, nVar);
                    bVar.debug("Source info fetched: " + this.c);
                    l.a(inputStream);
                } catch (IOException e2) {
                    e = e2;
                    f9932f.error("Error fetching info from " + this.c.a, e);
                    l.a(inputStream);
                    if (httpURLConnection == null) {
                        return;
                    }
                    httpURLConnection.disconnect();
                }
            } catch (Throwable th) {
                th = th;
                l.a(null);
                if (r1 != 0) {
                    r1.disconnect();
                }
                throw th;
            }
        } catch (IOException e3) {
            e = e3;
            httpURLConnection = null;
        } catch (Throwable th2) {
            th = th2;
            r1 = 0;
            l.a(null);
            if (r1 != 0) {
            }
            throw th;
        }
        httpURLConnection.disconnect();
    }

    public final HttpURLConnection c(long j2, int i2) throws IOException, ProxyCacheException {
        HttpURLConnection httpURLConnection;
        boolean z;
        String str = this.c.a;
        int i3 = 0;
        do {
            d.i.b bVar = f9932f;
            StringBuilder J = i.a.b.a.a.J("Open connection ");
            int i4 = (j2 > 0L ? 1 : (j2 == 0L ? 0 : -1));
            J.append(i4 > 0 ? i.a.b.a.a.l(" with offset ", j2) : "");
            J.append(" to ");
            J.append(str);
            bVar.debug(J.toString());
            httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            for (Map.Entry<String, String> entry : this.b.a(str).entrySet()) {
                httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
            }
            if (i4 > 0) {
                httpURLConnection.setRequestProperty("Range", i.a.b.a.a.n("bytes=", j2, "-"));
            }
            if (i2 > 0) {
                httpURLConnection.setConnectTimeout(i2);
                httpURLConnection.setReadTimeout(i2);
            }
            int responseCode = httpURLConnection.getResponseCode();
            z = responseCode == 301 || responseCode == 302 || responseCode == 303;
            if (z) {
                str = httpURLConnection.getHeaderField("Location");
                i3++;
                httpURLConnection.disconnect();
            }
            if (i3 > 5) {
                throw new ProxyCacheException(i.a.b.a.a.i("Too many redirects: ", i3));
            }
        } while (z);
        return httpURLConnection;
    }

    @Override
    public void close() throws ProxyCacheException {
        HttpURLConnection httpURLConnection = this.f9933d;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException e2) {
                f9932f.error("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 :(", e2);
            } catch (IllegalArgumentException 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);
            } catch (NullPointerException e4) {
                e = e4;
                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 synchronized long length() throws ProxyCacheException {
        if (this.c.b == -2147483648L) {
            b();
        }
        return this.c.b;
    }

    @Override
    public int read(byte[] bArr) throws ProxyCacheException {
        InputStream inputStream = this.f9934e;
        if (inputStream != null) {
            try {
                return inputStream.read(bArr, 0, bArr.length);
            } catch (InterruptedIOException e2) {
                throw new InterruptedProxyCacheException(i.a.b.a.a.A(i.a.b.a.a.J("Reading source "), this.c.a, " is interrupted"), e2);
            } catch (IOException e3) {
                StringBuilder J = i.a.b.a.a.J("Error reading data from ");
                J.append(this.c.a);
                throw new ProxyCacheException(J.toString(), e3);
            }
        }
        throw new ProxyCacheException(i.a.b.a.a.A(i.a.b.a.a.J("Error reading data from "), this.c.a, ": connection is absent!"));
    }

    public String toString() {
        StringBuilder J = i.a.b.a.a.J("HttpUrlSource{sourceInfo='");
        J.append(this.c);
        J.append("}");
        return J.toString();
    }

    public h(h hVar) {
        this.c = hVar.c;
        this.a = hVar.a;
        this.b = hVar.b;
    }
}