杏吧 v5.0版本的 MD5 值为:6060d82046650ce71383e136711e525f

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


package com.danikula.videocache;

import android.support.v4.media.a;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import androidx.annotation.NonNull;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import com.arialyy.aria.core.ProtocolType;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
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.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
public class HttpUrlSource implements Source {
    public final SourceInfoStorage f666a;
    public final HeaderInjector f667b;
    public final HostnameVerifier c;
    public final TrustManager[] d;
    public SourceInfo e;
    public HttpURLConnection f;
    public BufferedInputStream g;

    public HttpUrlSource(String str, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector, HostnameVerifier hostnameVerifier, TrustManager[] trustManagerArr) {
        sourceInfoStorage.getClass();
        this.f666a = sourceInfoStorage;
        headerInjector.getClass();
        this.f667b = headerInjector;
        this.c = hostnameVerifier;
        this.d = trustManagerArr;
        SourceInfo sourceInfo = sourceInfoStorage.get(str);
        if (sourceInfo == null) {
            MimeTypeMap singleton = MimeTypeMap.getSingleton();
            String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str);
            sourceInfo = new SourceInfo(-2147483648L, str, TextUtils.isEmpty(fileExtensionFromUrl) ? null : singleton.getMimeTypeFromExtension(fileExtensionFromUrl));
        }
        this.e = sourceInfo;
    }

    @Override
    public final void a(long j2) throws ProxyCacheException {
        long parseLong;
        try {
            HttpURLConnection c = c(-1, j2);
            this.f = c;
            String contentType = c.getContentType();
            this.g = new BufferedInputStream(this.f.getInputStream(), 8192);
            HttpURLConnection httpURLConnection = this.f;
            int responseCode = httpURLConnection.getResponseCode();
            String headerField = httpURLConnection.getHeaderField(RtspHeaders.CONTENT_LENGTH);
            if (headerField == null) {
                parseLong = -1;
            } else {
                parseLong = Long.parseLong(headerField);
            }
            if (responseCode != 200) {
                if (responseCode == 206) {
                    parseLong += j2;
                } else {
                    parseLong = this.e.f676b;
                }
            }
            String str = this.e.f675a;
            SourceInfo sourceInfo = new SourceInfo(parseLong, str, contentType);
            this.e = sourceInfo;
            this.f666a.b(str, sourceInfo);
        } catch (IOException e) {
            throw new ProxyCacheException("Error opening connection for " + this.e.f675a + " with offset " + j2, e);
        }
    }

    public final void b() throws ProxyCacheException {
        HttpURLConnection httpURLConnection;
        HttpURLConnection httpURLConnection2;
        long parseLong;
        InputStream inputStream = null;
        try {
            httpURLConnection2 = c(10000, 0L);
            try {
                try {
                    String headerField = httpURLConnection2.getHeaderField(RtspHeaders.CONTENT_LENGTH);
                    if (headerField == null) {
                        parseLong = -1;
                    } else {
                        parseLong = Long.parseLong(headerField);
                    }
                    String contentType = httpURLConnection2.getContentType();
                    inputStream = httpURLConnection2.getInputStream();
                    String str = this.e.f675a;
                    SourceInfo sourceInfo = new SourceInfo(parseLong, str, contentType);
                    this.e = sourceInfo;
                    this.f666a.b(str, sourceInfo);
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                            HttpProxyCacheDebuger.a("Error closing resource", e);
                        }
                    }
                } catch (IOException e2) {
                    e = e2;
                    HttpProxyCacheDebuger.a("Error fetching info from " + this.e.f675a, e);
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (IOException e3) {
                            HttpProxyCacheDebuger.a("Error closing resource", e3);
                        }
                    }
                    if (httpURLConnection2 == null) {
                        return;
                    }
                    httpURLConnection2.disconnect();
                }
            } catch (Throwable th) {
                th = th;
                inputStream = inputStream;
                httpURLConnection = httpURLConnection2;
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e4) {
                        HttpProxyCacheDebuger.a("Error closing resource", e4);
                    }
                }
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (IOException e5) {
            e = e5;
            httpURLConnection2 = null;
        } catch (Throwable th2) {
            th = th2;
            httpURLConnection = null;
            if (inputStream != null) {
            }
            if (httpURLConnection != null) {
            }
            throw th;
        }
        httpURLConnection2.disconnect();
    }

    public final HttpURLConnection c(int i2, long j2) throws IOException, ProxyCacheException {
        HttpURLConnection httpURLConnection;
        boolean z;
        long j3;
        HostnameVerifier hostnameVerifier;
        TrustManager[] trustManagerArr;
        String str = this.e.f675a;
        int i3 = 0;
        do {
            if (str.startsWith("https") && (hostnameVerifier = this.c) != null && (trustManagerArr = this.d) != null) {
                httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
                ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(hostnameVerifier);
                try {
                    SSLContext sSLContext = SSLContext.getInstance(ProtocolType.SSL);
                    sSLContext.init(null, trustManagerArr, new SecureRandom());
                    ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(sSLContext.getSocketFactory());
                    ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(hostnameVerifier);
                } catch (KeyManagementException | NoSuchAlgorithmException e) {
                    e.printStackTrace();
                }
            } else {
                httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
            }
            Map<String, String> addHeaders = this.f667b.addHeaders(str);
            if (addHeaders != null) {
                TextUtils.isEmpty("****** injectCustomHeaders ****** :" + addHeaders.size());
                for (Map.Entry<String, String> entry : addHeaders.entrySet()) {
                    httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
                }
            }
            if (j2 > 0) {
                if (j2 > 2147483647L) {
                    String valueOf = String.valueOf(j2);
                    if (valueOf.contains(".")) {
                        j3 = Long.valueOf(valueOf.substring(0, valueOf.indexOf("."))).longValue();
                    } else {
                        j3 = j2;
                    }
                    httpURLConnection.setRequestProperty(RtspHeaders.RANGE, "bytes=" + j3 + "-");
                } else {
                    httpURLConnection.setRequestProperty(RtspHeaders.RANGE, "bytes=" + ((int) j2) + "-");
                }
            }
            if (i2 > 0) {
                httpURLConnection.setConnectTimeout(i2);
                httpURLConnection.setReadTimeout(i2);
            }
            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode != 301 && responseCode != 302 && responseCode != 303) {
                z = false;
            } else {
                z = true;
            }
            if (z) {
                str = httpURLConnection.getHeaderField(RtspHeaders.LOCATION);
                i3++;
                httpURLConnection.disconnect();
            }
            if (i3 > 5) {
                throw new ProxyCacheException(a.l("Too many redirects: ", i3));
            }
        } while (z);
        return httpURLConnection;
    }

    @Override
    public final void close() throws ProxyCacheException {
        HttpURLConnection httpURLConnection = this.f;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (ArrayIndexOutOfBoundsException e) {
                HttpProxyCacheDebuger.a("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 :(", e);
            } catch (IllegalArgumentException 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 https://github.com/danikula or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
            } catch (NullPointerException 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 https://github.com/danikula or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
            }
        }
    }

    @Override
    public final synchronized long length() throws ProxyCacheException {
        if (this.e.f676b == -2147483648L) {
            b();
        }
        return this.e.f676b;
    }

    @Override
    public final int read(byte[] bArr) throws ProxyCacheException {
        BufferedInputStream bufferedInputStream = this.g;
        if (bufferedInputStream != null) {
            try {
                return bufferedInputStream.read(bArr, 0, bArr.length);
            } catch (InterruptedIOException e) {
                throw new InterruptedProxyCacheException(a.t(new StringBuilder("Reading source "), this.e.f675a, " is interrupted"), e);
            } catch (IOException e2) {
                throw new ProxyCacheException("Error reading data from " + this.e.f675a, e2);
            }
        }
        throw new ProxyCacheException(a.t(new StringBuilder("Error reading data from "), this.e.f675a, ": connection is absent!"));
    }

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

    public HttpUrlSource(HttpUrlSource httpUrlSource) {
        this.e = httpUrlSource.e;
        this.f666a = httpUrlSource.f666a;
        this.f667b = httpUrlSource.f667b;
        this.d = httpUrlSource.d;
        this.c = httpUrlSource.c;
    }
}