Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package com.liulishuo.filedownloader.connection;
import android.support.v4.media.session.PlaybackStateCompat;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
/* loaded from: classes.dex */
public class DefaultConnectionCountAdapter implements FileDownloadHelper.ConnectionCountAdapter {
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.ConnectionCountAdapter
public int a(int i, String str, String str2, long j) {
if (j < PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) {
return 1;
}
if (j < 5242880) {
return 2;
}
if (j < 52428800) {
return 3;
}
return j < 104857600 ? 4 : 5;
}
}

View File

@@ -0,0 +1,30 @@
package com.liulishuo.filedownloader.connection;
import java.io.IOException;
import java.io.InputStream;
import java.net.ProtocolException;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public interface FileDownloadConnection {
InputStream a() throws IOException;
String a(String str);
void a(String str, String str2);
boolean a(String str, long j);
Map<String, List<String>> b();
boolean b(String str) throws ProtocolException;
int c() throws IOException;
void d();
Map<String, List<String>> e();
void execute() throws IOException;
}

View File

@@ -0,0 +1,122 @@
package com.liulishuo.filedownloader.connection;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class FileDownloadUrlConnection implements FileDownloadConnection {
protected URLConnection a;
public static class Configuration {
private Proxy a;
private Integer b;
private Integer c;
}
public static class Creator implements FileDownloadHelper.ConnectionCreator {
private final Configuration a;
public Creator() {
this(null);
}
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.ConnectionCreator
public FileDownloadConnection a(String str) throws IOException {
return new FileDownloadUrlConnection(str, this.a);
}
public Creator(Configuration configuration) {
this.a = configuration;
}
}
public FileDownloadUrlConnection(String str, Configuration configuration) throws IOException {
this(new URL(str), configuration);
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void a(String str, String str2) {
this.a.addRequestProperty(str, str2);
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public boolean a(String str, long j) {
return false;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public Map<String, List<String>> b() {
return this.a.getHeaderFields();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public int c() throws IOException {
URLConnection uRLConnection = this.a;
if (uRLConnection instanceof HttpURLConnection) {
return ((HttpURLConnection) uRLConnection).getResponseCode();
}
return 0;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void d() {
try {
this.a.getInputStream().close();
} catch (IOException unused) {
}
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public Map<String, List<String>> e() {
return this.a.getRequestProperties();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void execute() throws IOException {
this.a.connect();
}
public FileDownloadUrlConnection(URL url, Configuration configuration) throws IOException {
if (configuration == null || configuration.a == null) {
this.a = url.openConnection();
} else {
this.a = url.openConnection(configuration.a);
}
if (configuration != null) {
if (configuration.b != null) {
this.a.setReadTimeout(configuration.b.intValue());
}
if (configuration.c != null) {
this.a.setConnectTimeout(configuration.c.intValue());
}
}
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public InputStream a() throws IOException {
return this.a.getInputStream();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public boolean b(String str) throws ProtocolException {
URLConnection uRLConnection = this.a;
if (!(uRLConnection instanceof HttpURLConnection)) {
return false;
}
((HttpURLConnection) uRLConnection).setRequestMethod(str);
return true;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public String a(String str) {
return this.a.getHeaderField(str);
}
}

View File

@@ -0,0 +1,61 @@
package com.liulishuo.filedownloader.connection;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class RedirectHandler {
public static FileDownloadConnection a(Map<String, List<String>> map, FileDownloadConnection fileDownloadConnection, List<String> list) throws IOException, IllegalAccessException {
int c = fileDownloadConnection.c();
String a = fileDownloadConnection.a("Location");
ArrayList arrayList = new ArrayList();
int i = 0;
while (a(c)) {
if (a == null) {
throw new IllegalAccessException(FileDownloadUtils.a("receive %d (redirect) but the location is null with response [%s]", Integer.valueOf(c), fileDownloadConnection.b()));
}
if (FileDownloadLog.a) {
FileDownloadLog.a(RedirectHandler.class, "redirect to %s with %d, %s", a, Integer.valueOf(c), arrayList);
}
fileDownloadConnection.d();
fileDownloadConnection = a(map, a);
arrayList.add(a);
fileDownloadConnection.execute();
c = fileDownloadConnection.c();
a = fileDownloadConnection.a("Location");
i++;
if (i >= 10) {
throw new IllegalAccessException(FileDownloadUtils.a("redirect too many times! %s", arrayList));
}
}
if (list != null) {
list.addAll(arrayList);
}
return fileDownloadConnection;
}
private static boolean a(int i) {
return i == 301 || i == 302 || i == 303 || i == 300 || i == 307 || i == 308;
}
private static FileDownloadConnection a(Map<String, List<String>> map, String str) throws IOException {
FileDownloadConnection a = CustomComponentHolder.i().a(str);
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> value = entry.getValue();
if (value != null) {
Iterator<String> it = value.iterator();
while (it.hasNext()) {
a.a(key, it.next());
}
}
}
return a;
}
}