123 lines
3.9 KiB
Java
123 lines
3.9 KiB
Java
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);
|
|
}
|
|
}
|