Amour v4.6.9版本的 MD5 值为:60db0759ce21a7c5858136dd0821206f

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


package w;

import android.text.TextUtils;
import android.util.Log;
import android.webkit.MimeTypeMap;
import com.just.agentweb.AgentWebPermissions;
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.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import ph.u0;
public final class k implements q {
    public final z.b f14720a;
    public final y.a f14721b;
    public r f14722c;
    public HttpURLConnection f14723d;
    public BufferedInputStream f14724e;

    public k(String str, z.b bVar, y.a aVar) {
        bVar.getClass();
        this.f14720a = bVar;
        aVar.getClass();
        this.f14721b = aVar;
        r rVar = bVar.get(str);
        if (rVar == null) {
            MimeTypeMap singleton = MimeTypeMap.getSingleton();
            String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str);
            rVar = new r(-2147483648L, str, TextUtils.isEmpty(fileExtensionFromUrl) ? null : singleton.getMimeTypeFromExtension(fileExtensionFromUrl));
        }
        this.f14722c = rVar;
    }

    @Override
    public final void a(long j10) throws p {
        long parseLong;
        try {
            HttpURLConnection c4 = c(-1, j10);
            this.f14723d = c4;
            String contentType = c4.getContentType();
            this.f14724e = new BufferedInputStream(this.f14723d.getInputStream(), 8192);
            HttpURLConnection httpURLConnection = this.f14723d;
            int responseCode = httpURLConnection.getResponseCode();
            String headerField = httpURLConnection.getHeaderField("Content-Length");
            if (headerField == null) {
                parseLong = -1;
            } else {
                parseLong = Long.parseLong(headerField);
            }
            if (responseCode != 200) {
                if (responseCode == 206) {
                    parseLong += j10;
                } else {
                    parseLong = this.f14722c.f14743b;
                }
            }
            String str = this.f14722c.f14742a;
            r rVar = new r(parseLong, str, contentType);
            this.f14722c = rVar;
            this.f14720a.g(str, rVar);
        } catch (IOException e10) {
            throw new p("Error opening connection for " + this.f14722c.f14742a + " with offset " + j10, e10);
        }
    }

    public final void b() throws p {
        HttpURLConnection httpURLConnection;
        HttpURLConnection httpURLConnection2;
        long parseLong;
        InputStream inputStream = null;
        try {
            httpURLConnection2 = c(10000, 0L);
            try {
                try {
                    String headerField = httpURLConnection2.getHeaderField("Content-Length");
                    if (headerField == null) {
                        parseLong = -1;
                    } else {
                        parseLong = Long.parseLong(headerField);
                    }
                    String contentType = httpURLConnection2.getContentType();
                    inputStream = httpURLConnection2.getInputStream();
                    String str = this.f14722c.f14742a;
                    r rVar = new r(parseLong, str, contentType);
                    this.f14722c = rVar;
                    this.f14720a.g(str, rVar);
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e10) {
                            u0.u0("Error closing resource", e10);
                        }
                    }
                } catch (IOException e11) {
                    e = e11;
                    u0.u0("Error fetching info from " + this.f14722c.f14742a, e);
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e12) {
                            u0.u0("Error closing resource", e12);
                        }
                    }
                    if (httpURLConnection2 == null) {
                        return;
                    }
                    httpURLConnection2.disconnect();
                }
            } catch (Throwable th2) {
                th = th2;
                inputStream = inputStream;
                httpURLConnection = httpURLConnection2;
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e13) {
                        u0.u0("Error closing resource", e13);
                    }
                }
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (IOException e14) {
            e = e14;
            httpURLConnection2 = null;
        } catch (Throwable th3) {
            th = th3;
            httpURLConnection = null;
            if (inputStream != null) {
            }
            if (httpURLConnection != null) {
            }
            throw th;
        }
        httpURLConnection2.disconnect();
    }

    public final HttpURLConnection c(int i, long j10) throws IOException, p {
        boolean z10;
        HttpURLConnection httpURLConnection;
        String str = this.f14722c.f14742a;
        int i10 = 0;
        do {
            z10 = true;
            if (str.startsWith("https")) {
                httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
                ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(new h());
                TrustManager[] trustManagerArr = {new i()};
                try {
                    SSLContext sSLContext = SSLContext.getInstance("SSL");
                    sSLContext.init(null, trustManagerArr, new SecureRandom());
                    ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(sSLContext.getSocketFactory());
                    ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(new j());
                } catch (KeyManagementException e10) {
                    e10.printStackTrace();
                } catch (NoSuchAlgorithmException e11) {
                    e11.printStackTrace();
                }
            } else {
                httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            }
            HashMap a10 = this.f14721b.a();
            if (a10 != null) {
                String str2 = "****** injectCustomHeaders ****** :" + a10.size();
                if (!TextUtils.isEmpty(str2)) {
                    Log.e("HttpProxyCacheDebuger", str2);
                }
                for (Map.Entry entry : a10.entrySet()) {
                    httpURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
                }
            }
            if (j10 > 0) {
                httpURLConnection.setRequestProperty("Range", "bytes=" + j10 + "-");
            }
            if (i > 0) {
                httpURLConnection.setConnectTimeout(i);
                httpURLConnection.setReadTimeout(i);
            }
            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode != 301 && responseCode != 302 && responseCode != 303) {
                z10 = false;
            }
            if (z10) {
                str = httpURLConnection.getHeaderField(AgentWebPermissions.ACTION_LOCATION);
                i10++;
                httpURLConnection.disconnect();
            }
            if (i10 > 5) {
                throw new p(a1.i.d("Too many redirects: ", i10));
            }
        } while (z10);
        return httpURLConnection;
    }

    @Override
    public final void close() throws p {
        HttpURLConnection httpURLConnection = this.f14723d;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException e10) {
                u0.u0("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 :(", e10);
            } catch (IllegalArgumentException e11) {
                e = e11;
                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 e12) {
                e = e12;
                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() throws p {
        if (this.f14722c.f14743b == -2147483648L) {
            b();
        }
        return this.f14722c.f14743b;
    }

    @Override
    public final int read(byte[] bArr) throws p {
        BufferedInputStream bufferedInputStream = this.f14724e;
        if (bufferedInputStream != null) {
            try {
                return bufferedInputStream.read(bArr, 0, bArr.length);
            } catch (InterruptedIOException e10) {
                throw new m(androidx.appcompat.graphics.drawable.a.i(new StringBuilder("Reading source "), this.f14722c.f14742a, " is interrupted"), e10);
            } catch (IOException e11) {
                throw new p("Error reading data from " + this.f14722c.f14742a, e11);
            }
        }
        throw new p(androidx.appcompat.graphics.drawable.a.i(new StringBuilder("Error reading data from "), this.f14722c.f14742a, ": connection is absent!"));
    }

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

    public k(k kVar) {
        this.f14722c = kVar.f14722c;
        this.f14720a = kVar.f14720a;
        this.f14721b = kVar.f14721b;
    }
}