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

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


package com.sigmob.sdk.videocache;

import android.text.TextUtils;
import com.czhj.sdk.logger.SigmobLog;
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 class j implements s {
    private static final int a = 5;
    private final com.sigmob.sdk.videocache.sourcestorage.c b;
    private final com.sigmob.sdk.videocache.headers.b c;
    private t f11485d;
    private HttpURLConnection f11486e;
    private InputStream f11487f;

    public j(j jVar) {
        this.f11485d = jVar.f11485d;
        this.b = jVar.b;
        this.c = jVar.c;
    }

    public j(String str) {
        this(str, com.sigmob.sdk.videocache.sourcestorage.d.a());
    }

    public j(String str, com.sigmob.sdk.videocache.sourcestorage.c cVar) {
        this(str, cVar, new com.sigmob.sdk.videocache.headers.a());
    }

    public j(String str, com.sigmob.sdk.videocache.sourcestorage.c cVar, com.sigmob.sdk.videocache.headers.b bVar) {
        this.b = (com.sigmob.sdk.videocache.sourcestorage.c) n.a(cVar);
        this.c = (com.sigmob.sdk.videocache.headers.b) n.a(bVar);
        t a2 = cVar.a(str);
        this.f11485d = a2 == null ? new t(str, -2147483648L, q.a(str)) : a2;
    }

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

    private long a(HttpURLConnection httpURLConnection, long j, int i2) throws IOException {
        long a2 = a(httpURLConnection);
        return i2 == 200 ? a2 : i2 == 206 ? a2 + j : this.f11485d.b;
    }

    private HttpURLConnection a(long j, int i2) throws IOException, p {
        String str;
        HttpURLConnection httpURLConnection;
        boolean z;
        String str2 = this.f11485d.a;
        int i3 = 0;
        do {
            StringBuilder sb = new StringBuilder();
            sb.append("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);
            SigmobLog.d(sb.toString());
            httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
            a(httpURLConnection, str2);
            if (i4 > 0) {
                httpURLConnection.setRequestProperty("Range", "bytes=" + j + "-");
            }
            if (i2 > 0) {
                httpURLConnection.setConnectTimeout(i2);
                httpURLConnection.setReadTimeout(i2);
            }
            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 p("Too many redirects: " + i3);
            }
        } while (z);
        return httpURLConnection;
    }

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

    private void e() throws p {
        HttpURLConnection httpURLConnection;
        SigmobLog.d("Read content info from " + this.f11485d.a);
        ?? r0 = 0;
        InputStream inputStream = null;
        try {
            try {
                httpURLConnection = a(0L, 10000);
                try {
                    long a2 = a(httpURLConnection);
                    String contentType = httpURLConnection.getContentType();
                    inputStream = httpURLConnection.getInputStream();
                    t tVar = new t(this.f11485d.a, a2, contentType);
                    this.f11485d = tVar;
                    this.b.a(tVar.a, tVar);
                    SigmobLog.d("Source info fetched: " + this.f11485d);
                    q.a(inputStream);
                    r0 = httpURLConnection;
                    if (httpURLConnection == null) {
                        return;
                    }
                } catch (IOException e2) {
                    e = e2;
                    SigmobLog.e("Error fetching info from " + this.f11485d.a, e);
                    q.a(inputStream);
                    r0 = httpURLConnection;
                    if (httpURLConnection == null) {
                        return;
                    }
                    r0.disconnect();
                }
            } catch (Throwable th) {
                th = th;
                q.a(inputStream);
                if (r0 != 0) {
                    r0.disconnect();
                }
                throw th;
            }
        } catch (IOException e3) {
            e = e3;
            httpURLConnection = null;
        } catch (Throwable th2) {
            th = th2;
            r0 = 0;
            q.a(inputStream);
            if (r0 != 0) {
            }
            throw th;
        }
        r0.disconnect();
    }

    @Override
    public int a(byte[] bArr) throws p {
        InputStream inputStream = this.f11487f;
        if (inputStream == null) {
            throw new p("Error reading data from " + this.f11485d.a + ": connection is absent!");
        }
        try {
            return inputStream.read(bArr, 0, bArr.length);
        } catch (InterruptedIOException e2) {
            throw new l("Reading source " + this.f11485d.a + " is interrupted", e2);
        } catch (IOException e3) {
            throw new p("Error reading data from " + this.f11485d.a, e3);
        }
    }

    @Override
    public synchronized long a() throws p {
        if (this.f11485d.b == -2147483648L) {
            e();
        }
        return this.f11485d.b;
    }

    @Override
    public void a(long j) throws p {
        try {
            HttpURLConnection a2 = a(j, -1);
            this.f11486e = a2;
            String contentType = a2.getContentType();
            this.f11487f = new BufferedInputStream(this.f11486e.getInputStream(), 8192);
            t tVar = new t(this.f11485d.a, a(this.f11486e, j, this.f11486e.getResponseCode()), contentType);
            this.f11485d = tVar;
            this.b.a(tVar.a, tVar);
        } catch (IOException e2) {
            throw new p("Error opening connection for " + this.f11485d.a + " with offset " + j, e2);
        }
    }

    @Override
    public void b() throws p {
        HttpURLConnection httpURLConnection = this.f11486e;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException e2) {
                SigmobLog.e("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);
            }
        }
    }

    public synchronized String c() throws p {
        if (TextUtils.isEmpty(this.f11485d.c)) {
            e();
        }
        return this.f11485d.c;
    }

    public String d() {
        return this.f11485d.a;
    }

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