最右.apk(点击下载) / d.java


package com.tencent.klevin.e.j;

import com.alibaba.sdk.android.oss.common.utils.HttpHeaders;
import com.alipay.sdk.util.h;
import com.tencent.klevin.e.j.w.b;
import java.io.BufferedInputStream;
import java.io.Closeable;
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 class d implements p {

    /* renamed from: a  reason: collision with root package name */
    private final b f23484a;

    /* renamed from: b  reason: collision with root package name */
    private final com.tencent.klevin.e.j.v.b f23485b;
    private q c;
    private HttpURLConnection d;
    private InputStream e;

    public d(String str, b bVar, com.tencent.klevin.e.j.v.b bVar2) {
        this.f23485b = bVar2;
        this.f23484a = bVar;
        q a2 = bVar != null ? bVar.a(str) : null;
        this.c = a2 == null ? new q(str, -2147483648L, n.b(str)) : a2;
    }

    /* JADX WARNING: Removed duplicated region for block: B:22:0x008b  */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0096  */
    /* JADX WARNING: Removed duplicated region for block: B:31:? A[RETURN, SYNTHETIC] */
    private void c() {
        Throwable th;
        Closeable closeable;
        HttpURLConnection httpURLConnection;
        IOException e2;
        t.a("VideoCache_HttpUrlSource", "Read content info from " + this.c.f23498a);
        HttpURLConnection httpURLConnection2 = null;
        try {
            httpURLConnection = a(0, 10000);
            try {
                long a2 = a(httpURLConnection);
                String contentType = httpURLConnection.getContentType();
                InputStream inputStream = httpURLConnection.getInputStream();
                q qVar = new q(this.c.f23498a, a2, contentType);
                this.c = qVar;
                b bVar = this.f23484a;
                if (bVar != null) {
                    bVar.a(qVar.f23498a, qVar);
                }
                t.a("VideoCache_HttpUrlSource", "Source info fetched: " + this.c);
                n.a(inputStream);
                if (httpURLConnection == null) {
                    return;
                }
            } catch (IOException e3) {
                e2 = e3;
                httpURLConnection2 = httpURLConnection;
                closeable = null;
                try {
                    t.a("VideoCache_HttpUrlSource", "Error fetching info from " + this.c.f23498a, e2);
                    n.a(closeable);
                    if (httpURLConnection2 == null) {
                        httpURLConnection = httpURLConnection2;
                        httpURLConnection.disconnect();
                    }
                    return;
                } catch (Throwable th2) {
                    th = th2;
                    n.a(closeable);
                    if (httpURLConnection2 != null) {
                        httpURLConnection2.disconnect();
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                httpURLConnection2 = httpURLConnection;
                closeable = null;
                n.a(closeable);
                if (httpURLConnection2 != null) {
                }
                throw th;
            }
        } catch (IOException e4) {
            e2 = e4;
            closeable = null;
            t.a("VideoCache_HttpUrlSource", "Error fetching info from " + this.c.f23498a, e2);
            n.a(closeable);
            if (httpURLConnection2 == null) {
            }
        } catch (Throwable th4) {
            th = th4;
            closeable = null;
            n.a(closeable);
            if (httpURLConnection2 != null) {
            }
            throw th;
        }
        httpURLConnection.disconnect();
    }

    @Override // com.tencent.klevin.e.j.p
    public synchronized long a() {
        if (this.c.f23499b == -2147483648L) {
            c();
        }
        return this.c.f23499b;
    }

    public String b() {
        return this.c.f23498a;
    }

    @Override // com.tencent.klevin.e.j.p
    public void close() {
        HttpURLConnection httpURLConnection = this.d;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (IllegalArgumentException | NullPointerException 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.", e2);
            } catch (ArrayIndexOutOfBoundsException e3) {
                t.a("VideoCache_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 :(", e3);
            }
        }
    }

    public String toString() {
        return "HttpUrlSource{sourceInfo='" + this.c + h.d;
    }

    @Override // com.tencent.klevin.e.j.p
    public void a(long j) {
        try {
            HttpURLConnection a2 = a(j, -1);
            this.d = a2;
            String contentType = a2.getContentType();
            this.e = new BufferedInputStream(this.d.getInputStream(), 8192);
            HttpURLConnection httpURLConnection = this.d;
            q qVar = new q(this.c.f23498a, a(httpURLConnection, j, httpURLConnection.getResponseCode()), contentType);
            this.c = qVar;
            b bVar = this.f23484a;
            if (bVar != null) {
                bVar.a(qVar.f23498a, qVar);
            }
        } catch (IOException e2) {
            throw new m("Error opening connection for " + this.c.f23498a + " with offset " + j, e2);
        }
    }

    private long a(HttpURLConnection httpURLConnection, long j, int i) {
        long a2 = a(httpURLConnection);
        if (i == 200) {
            return a2;
        }
        if (i == 206) {
            return a2 + j;
        }
        return this.c.f23499b;
    }

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

    @Override // com.tencent.klevin.e.j.p
    public int a(byte[] bArr) {
        InputStream inputStream = this.e;
        if (inputStream != null) {
            try {
                return inputStream.read(bArr, 0, bArr.length);
            } catch (InterruptedIOException e2) {
                throw new g("Reading source " + this.c.f23498a + " is interrupted", e2);
            } catch (IOException e3) {
                throw new m("Error reading data from " + this.c.f23498a, e3);
            }
        } else {
            throw new m("Error reading data from " + this.c.f23498a + ": connection is absent!");
        }
    }

    private HttpURLConnection a(long j, int i) {
        String str;
        HttpURLConnection httpURLConnection;
        boolean z;
        String str2 = this.c.f23498a;
        int i2 = 0;
        do {
            StringBuilder sb = new StringBuilder();
            sb.append("Open connection ");
            int i3 = (j > 0 ? 1 : (j == 0 ? 0 : -1));
            if (i3 > 0) {
                str = " with offset " + j;
            } else {
                str = "";
            }
            sb.append(str);
            sb.append(" to ");
            sb.append(str2);
            t.a("VideoCache_HttpUrlSource", sb.toString());
            httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
            a(httpURLConnection, str2);
            if (i3 > 0) {
                httpURLConnection.setRequestProperty(HttpHeaders.RANGE, "bytes=" + j + "-");
            }
            if (i > 0) {
                httpURLConnection.setConnectTimeout(i);
                httpURLConnection.setReadTimeout(i);
            }
            int responseCode = httpURLConnection.getResponseCode();
            z = responseCode == 301 || responseCode == 302 || responseCode == 303;
            if (z) {
                str2 = httpURLConnection.getHeaderField(HttpHeaders.LOCATION);
                i2++;
                httpURLConnection.disconnect();
            }
            if (i2 > 5) {
                throw new m("Too many redirects: " + i2);
            }
        } while (z);
        return httpURLConnection;
    }

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