正在查看: 哔哩哔哩 v1.6.6 应用的 OkHttpURLConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 哔哩哔哩 v1.6.6 应用的 OkHttpURLConnection.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.bilibili.lib.okhttp.huc;
import bl.bhb;
import bl.bhd;
import bl.bhe;
import bl.bhm;
import bl.bhq;
import bl.bhr;
import bl.bhs;
import bl.bhv;
import bl.bhx;
import bl.bhz;
import bl.bic;
import bl.bif;
import bl.biv;
import bl.biw;
import bl.bix;
import bl.bjc;
import bl.bjw;
import bl.bke;
import bl.uu;
import bl.uw;
import bl.uy;
import bl.uz;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.SocketPermission;
import java.net.URL;
import java.security.Permission;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import okhttp3.HttpUrl;
public final class OkHttpURLConnection extends HttpURLConnection implements bhe {
public static final String a = bjw.c().d() + "-Selected-Protocol";
public static final String b = bjw.c().d() + "-Response-Source";
private static final Set<String> i = new LinkedHashSet(Arrays.asList("OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "PATCH"));
public bhv c;
public bhd d;
bhz e;
boolean f;
Proxy g;
public bhq h;
private final a j;
private bhr.a k;
private boolean l;
private bhr m;
private long n;
private final Object o;
private bhz p;
private Throwable q;
public OkHttpURLConnection(URL url, bhv bhvVar) {
super(url);
this.j = new a();
this.k = new bhr.a();
this.n = -1L;
this.o = new Object();
this.f = true;
this.c = bhvVar;
}
@Override
public void connect() throws IOException {
if (this.l) {
return;
}
bhd b2 = b();
this.l = true;
b2.a(this);
synchronized (this.o) {
while (this.f && this.p == null && this.q == null) {
try {
try {
this.o.wait();
} catch (InterruptedException unused) {
throw new InterruptedIOException();
}
} catch (Throwable th) {
throw th;
}
}
if (this.q != null) {
throw a(this.q);
}
}
}
@Override
public void disconnect() {
if (this.d == null) {
return;
}
this.j.a();
this.d.c();
if (this.p != null) {
this.p.close();
this.p = null;
}
if (this.e != null) {
this.e.close();
this.e = null;
}
}
@Override
public InputStream getErrorStream() {
try {
bhz a2 = a(true);
if (!biw.b(a2) || a2.c() < 400) {
return null;
}
return a2.h().d();
} catch (IOException unused) {
return null;
}
}
private bhr a() throws IOException {
if (this.m == null) {
bhz a2 = a(true);
this.m = a2.g().b().a(a, a2.b().toString()).a(b, a(a2)).a();
}
return this.m;
}
private static String a(bhz bhzVar) {
if (bhzVar.j() == null) {
if (bhzVar.k() == null) {
return "NONE";
}
return "CACHE " + bhzVar.c();
}
if (bhzVar.k() == null) {
return "NETWORK " + bhzVar.c();
}
return "CONDITIONAL_CACHE " + bhzVar.j().c();
}
@Override
public String getHeaderField(int i2) {
try {
bhr a2 = a();
if (i2 >= 0 && i2 < a2.a()) {
return a2.b(i2);
}
return null;
} catch (IOException unused) {
return null;
}
}
@Override
public String getHeaderField(String str) {
String a2;
try {
if (str == null) {
a2 = bjc.a(a(true)).toString();
} else {
a2 = a().a(str);
}
return a2;
} catch (IOException unused) {
return null;
}
}
@Override
public String getHeaderFieldKey(int i2) {
try {
bhr a2 = a();
if (i2 >= 0 && i2 < a2.a()) {
return a2.a(i2);
}
return null;
} catch (IOException unused) {
return null;
}
}
@Override
public Map<String, List<String>> getHeaderFields() {
try {
return uw.a(a(), bjc.a(a(true)).toString());
} catch (IOException unused) {
return Collections.emptyMap();
}
}
@Override
public Map<String, List<String>> getRequestProperties() {
if (this.connected) {
throw new IllegalStateException("Cannot access request header fields after connection is set");
}
return uw.a(this.k.a(), null);
}
@Override
public InputStream getInputStream() throws IOException {
if (!this.doInput) {
throw new ProtocolException("This protocol does not support input");
}
bhz a2 = a(false);
if (a2.c() >= 400) {
throw new FileNotFoundException(this.url.toString());
}
return a2.h().d();
}
@Override
public OutputStream getOutputStream() throws IOException {
uy uyVar = (uy) b().a().d();
if (uyVar == null) {
throw new ProtocolException("method does not support a request body: " + this.method);
}
if (uyVar instanceof uz) {
connect();
this.j.a();
}
if (uyVar.d()) {
throw new ProtocolException("cannot write request body after response has been read");
}
return uyVar.b();
}
@Override
public Permission getPermission() throws IOException {
int a2;
URL url = getURL();
String host = url.getHost();
if (url.getPort() != -1) {
a2 = url.getPort();
} else {
a2 = HttpUrl.a(url.getProtocol());
}
if (usingProxy()) {
InetSocketAddress inetSocketAddress = (InetSocketAddress) this.c.e().address();
host = inetSocketAddress.getHostName();
a2 = inetSocketAddress.getPort();
}
return new SocketPermission(host + ":" + a2, "connect, resolve");
}
@Override
public String getRequestProperty(String str) {
if (str == null) {
return null;
}
return this.k.d(str);
}
@Override
public void setConnectTimeout(int i2) {
this.c = this.c.z().a(i2, TimeUnit.MILLISECONDS).c();
}
@Override
public void setInstanceFollowRedirects(boolean z) {
this.c = this.c.z().a(z).c();
}
@Override
public boolean getInstanceFollowRedirects() {
return this.c.r();
}
@Override
public int getConnectTimeout() {
return this.c.a();
}
@Override
public void setReadTimeout(int i2) {
this.c = this.c.z().b(i2, TimeUnit.MILLISECONDS).c();
}
@Override
public int getReadTimeout() {
return this.c.b();
}
private bhd b() throws IOException {
uy uyVar;
if (this.d != null) {
return this.d;
}
boolean z = true;
this.connected = true;
if (this.doOutput) {
if (this.method.equals("GET")) {
this.method = "POST";
} else if (!bix.c(this.method)) {
throw new ProtocolException(this.method + " does not support writing");
}
}
if (this.k.d("User-Agent") == null) {
this.k.a("User-Agent", c());
}
if (bix.c(this.method)) {
if (this.k.d("Content-Type") == null) {
this.k.a("Content-Type", "application/x-www-form-urlencoded");
}
long j = -1;
if (this.n == -1 && this.chunkLength <= 0) {
z = false;
}
String d = this.k.d("Content-Length");
if (this.n != -1) {
j = this.n;
} else if (d != null) {
j = Long.parseLong(d);
}
uyVar = z ? new uz(j) : new uu(j);
uyVar.c().a(this.c.c(), TimeUnit.MILLISECONDS);
} else {
uyVar = null;
}
bhx b2 = new bhx.a().a(bic.a.a(getURL().toString())).a(this.k.a()).a(this.method, uyVar).b();
bhv.a z2 = this.c.z();
z2.a().clear();
z2.a().add(UnexpectedException.INTERCEPTOR);
z2.b().add(0, this.j);
z2.a(new bhm(this.c.t().a()));
if (!getUseCaches()) {
z2.a((bhb) null);
}
bhd a2 = z2.c().a(b2);
this.d = a2;
return a2;
}
private String c() {
String property = System.getProperty("http.agent");
return property != null ? a(property) : bif.a();
}
private static String a(String str) {
int length = str.length();
int i2 = 0;
while (i2 < length) {
int codePointAt = str.codePointAt(i2);
if (codePointAt > 31 && codePointAt < 127) {
i2 += Character.charCount(codePointAt);
} else {
bke bkeVar = new bke();
bkeVar.a(str, 0, i2);
bkeVar.a(63);
while (true) {
i2 += Character.charCount(codePointAt);
if (i2 < length) {
codePointAt = str.codePointAt(i2);
bkeVar.a((codePointAt <= 31 || codePointAt >= 127) ? 63 : codePointAt);
} else {
return bkeVar.p();
}
}
}
}
return str;
}
private bhz a(boolean z) throws IOException {
synchronized (this.o) {
if (this.p != null) {
return this.p;
}
if (this.q != null) {
if (!z || this.e == null) {
throw a(this.q);
}
return this.e;
}
bhd b2 = b();
this.j.a();
uy uyVar = (uy) b2.a().d();
if (uyVar != null) {
uyVar.b().close();
}
if (this.l) {
synchronized (this.o) {
while (this.p == null && this.q == null) {
try {
try {
this.o.wait();
} catch (InterruptedException unused) {
throw new InterruptedIOException();
}
} finally {
}
}
}
} else {
this.l = true;
try {
a(b2, b2.b());
} catch (IOException e) {
a(b2, e);
}
}
synchronized (this.o) {
if (this.q != null) {
throw a(this.q);
}
if (this.p == null) {
throw new AssertionError();
}
return this.p;
}
}
}
@Override
public boolean usingProxy() {
if (this.g != null) {
return true;
}
Proxy e = this.c.e();
return (e == null || e.type() == Proxy.Type.DIRECT) ? false : true;
}
@Override
public String getResponseMessage() throws IOException {
return a(true).e();
}
@Override
public int getResponseCode() throws IOException {
return a(true).c();
}
@Override
public void setRequestProperty(String str, String str2) {
if (this.connected) {
throw new IllegalStateException("Cannot set request property after connection is made");
}
if (str == null) {
throw new NullPointerException("field == null");
}
if (str2 == null) {
bjw.c().a(5, "Ignoring header " + str + " because its value was null.", (Throwable) null);
return;
}
this.k.c(str, str2);
}
@Override
public void setIfModifiedSince(long j) {
super.setIfModifiedSince(j);
if (this.ifModifiedSince != 0) {
this.k.c("If-Modified-Since", biv.a(new Date(this.ifModifiedSince)));
} else {
this.k.c("If-Modified-Since");
}
}
@Override
public void addRequestProperty(String str, String str2) {
if (this.connected) {
throw new IllegalStateException("Cannot add request property after connection is made");
}
if (str == null) {
throw new NullPointerException("field == null");
}
if (str2 == null) {
bjw.c().a(5, "Ignoring header " + str + " because its value was null.", (Throwable) null);
return;
}
this.k.a(str, str2);
}
@Override
public void setRequestMethod(String str) throws ProtocolException {
if (!i.contains(str)) {
throw new ProtocolException("Expected one of " + i + " but was " + str);
}
this.method = str;
}
@Override
public void setFixedLengthStreamingMode(int i2) {
setFixedLengthStreamingMode(i2);
}
@Override
public void setFixedLengthStreamingMode(long j) {
if (((HttpURLConnection) this).connected) {
throw new IllegalStateException("Already connected");
}
if (this.chunkLength > 0) {
throw new IllegalStateException("Already in chunked mode");
}
if (j < 0) {
throw new IllegalArgumentException("contentLength < 0");
}
this.n = j;
((HttpURLConnection) this).fixedContentLength = (int) Math.min(j, 2147483647L);
}
@Override
public void a(bhd bhdVar, IOException iOException) {
synchronized (this.o) {
boolean z = iOException instanceof UnexpectedException;
Throwable th = iOException;
if (z) {
th = iOException.getCause();
}
this.q = th;
this.o.notifyAll();
}
}
@Override
public void a(bhd bhdVar, bhz bhzVar) {
synchronized (this.o) {
this.p = bhzVar;
this.h = bhzVar.f();
this.url = bhzVar.a().a().a();
this.o.notifyAll();
}
}
static final class UnexpectedException extends IOException {
static final bhs INTERCEPTOR = new bhs() {
@Override
public bhz a(bhs.a aVar) throws IOException {
try {
return aVar.a(aVar.a());
} catch (Error | RuntimeException e) {
throw new UnexpectedException(e);
}
}
};
public UnexpectedException(Throwable th) {
super(th);
}
}
private static IOException a(Throwable th) throws IOException {
if (th instanceof IOException) {
throw ((IOException) th);
}
if (th instanceof Error) {
throw ((Error) th);
}
if (th instanceof RuntimeException) {
throw ((RuntimeException) th);
}
throw new AssertionError();
}
final class a implements bhs {
private boolean b;
a() {
}
public void a() {
synchronized (OkHttpURLConnection.this.o) {
this.b = true;
OkHttpURLConnection.this.o.notifyAll();
}
}
@Override
public bhz a(bhs.a aVar) throws IOException {
bhx a = aVar.a();
synchronized (OkHttpURLConnection.this.o) {
OkHttpURLConnection.this.f = false;
OkHttpURLConnection.this.g = aVar.b().a().b();
OkHttpURLConnection.this.h = aVar.b().b();
OkHttpURLConnection.this.o.notifyAll();
while (!this.b) {
try {
OkHttpURLConnection.this.o.wait();
} catch (InterruptedException unused) {
throw new InterruptedIOException();
}
}
}
if (a.d() instanceof uy) {
a = ((uy) a.d()).a(a);
}
bhz a2 = aVar.a(a);
synchronized (OkHttpURLConnection.this.o) {
OkHttpURLConnection.this.e = a2;
OkHttpURLConnection.this.url = a2.a().a().a();
}
return a2;
}
}
}