340 lines
12 KiB
Java
340 lines
12 KiB
Java
|
package okhttp3;
|
||
|
|
||
|
import java.io.Closeable;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.io.InputStreamReader;
|
||
|
import java.io.Reader;
|
||
|
import java.nio.charset.Charset;
|
||
|
import o.C14866gag;
|
||
|
import o.C14953gcr;
|
||
|
import o.C14957gcv;
|
||
|
import o.C15111ghZ;
|
||
|
import o.C15155gij;
|
||
|
import o.InterfaceC14894gbR;
|
||
|
import o.InterfaceC15149gid;
|
||
|
import o.gbF;
|
||
|
import o.gdP;
|
||
|
import okhttp3.MediaType;
|
||
|
import okhttp3.internal.Util;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public abstract class ResponseBody implements Closeable {
|
||
|
public static final Companion Companion = new Companion(null);
|
||
|
private Reader reader;
|
||
|
|
||
|
public abstract long contentLength();
|
||
|
|
||
|
public abstract MediaType contentType();
|
||
|
|
||
|
public abstract InterfaceC15149gid source();
|
||
|
|
||
|
public final InputStream byteStream() {
|
||
|
return source().h();
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Type inference failed for: r5v3, types: [T, java.lang.Object] */
|
||
|
private final <T> T consumeSource(InterfaceC14894gbR<? super InterfaceC15149gid, ? extends T> interfaceC14894gbR, InterfaceC14894gbR<? super T, Integer> interfaceC14894gbR2) {
|
||
|
long contentLength = contentLength();
|
||
|
if (contentLength > 2147483647L) {
|
||
|
throw new IOException(C14957gcv.c("Cannot buffer entire body for content length: ", Long.valueOf(contentLength)));
|
||
|
}
|
||
|
InterfaceC15149gid source = source();
|
||
|
try {
|
||
|
T invoke = interfaceC14894gbR.invoke(source);
|
||
|
gbF.d(source, null);
|
||
|
int intValue = interfaceC14894gbR2.invoke(invoke).intValue();
|
||
|
if (contentLength == -1 || contentLength == intValue) {
|
||
|
return invoke;
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder("Content-Length (");
|
||
|
sb.append(contentLength);
|
||
|
sb.append(") and stream length (");
|
||
|
sb.append(intValue);
|
||
|
sb.append(") disagree");
|
||
|
throw new IOException(sb.toString());
|
||
|
} finally {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final Reader charStream() {
|
||
|
Reader reader = this.reader;
|
||
|
if (reader != null) {
|
||
|
return reader;
|
||
|
}
|
||
|
BomAwareReader bomAwareReader = new BomAwareReader(source(), charset());
|
||
|
this.reader = bomAwareReader;
|
||
|
return bomAwareReader;
|
||
|
}
|
||
|
|
||
|
public final String string() throws IOException {
|
||
|
InterfaceC15149gid source = source();
|
||
|
try {
|
||
|
InterfaceC15149gid interfaceC15149gid = source;
|
||
|
String d = interfaceC15149gid.d(Util.readBomAsCharset(interfaceC15149gid, charset()));
|
||
|
gbF.d(source, null);
|
||
|
return d;
|
||
|
} finally {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final Charset charset() {
|
||
|
MediaType contentType = contentType();
|
||
|
Charset charset = contentType == null ? null : contentType.charset(gdP.a);
|
||
|
return charset == null ? gdP.a : charset;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
||
|
public void close() {
|
||
|
Util.closeQuietly(source());
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public static final class BomAwareReader extends Reader {
|
||
|
private final Charset charset;
|
||
|
private boolean closed;
|
||
|
private Reader delegate;
|
||
|
private final InterfaceC15149gid source;
|
||
|
|
||
|
public BomAwareReader(InterfaceC15149gid interfaceC15149gid, Charset charset) {
|
||
|
C14957gcv.e(interfaceC15149gid, "");
|
||
|
C14957gcv.e(charset, "");
|
||
|
this.source = interfaceC15149gid;
|
||
|
this.charset = charset;
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Reader
|
||
|
public final int read(char[] cArr, int i, int i2) throws IOException {
|
||
|
C14957gcv.e(cArr, "");
|
||
|
if (this.closed) {
|
||
|
throw new IOException("Stream closed");
|
||
|
}
|
||
|
InputStreamReader inputStreamReader = this.delegate;
|
||
|
if (inputStreamReader == null) {
|
||
|
inputStreamReader = new InputStreamReader(this.source.h(), Util.readBomAsCharset(this.source, this.charset));
|
||
|
this.delegate = inputStreamReader;
|
||
|
}
|
||
|
return inputStreamReader.read(cArr, i, i2);
|
||
|
}
|
||
|
|
||
|
@Override // java.io.Reader, java.io.Closeable, java.lang.AutoCloseable
|
||
|
public final void close() throws IOException {
|
||
|
C14866gag c14866gag;
|
||
|
this.closed = true;
|
||
|
Reader reader = this.delegate;
|
||
|
if (reader == null) {
|
||
|
c14866gag = null;
|
||
|
} else {
|
||
|
reader.close();
|
||
|
c14866gag = C14866gag.c;
|
||
|
}
|
||
|
if (c14866gag == null) {
|
||
|
this.source.close();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public static final class Companion {
|
||
|
private Companion() {
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ ResponseBody create$default(Companion companion, String str, MediaType mediaType, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
mediaType = null;
|
||
|
}
|
||
|
return companion.create(str, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(String str, MediaType mediaType) {
|
||
|
C14957gcv.e(str, "");
|
||
|
Charset charset = gdP.a;
|
||
|
if (mediaType != null && (charset = MediaType.charset$default(mediaType, null, 1, null)) == null) {
|
||
|
charset = gdP.a;
|
||
|
MediaType.Companion companion = MediaType.Companion;
|
||
|
StringBuilder sb = new StringBuilder();
|
||
|
sb.append(mediaType);
|
||
|
sb.append("; charset=utf-8");
|
||
|
mediaType = companion.parse(sb.toString());
|
||
|
}
|
||
|
C15111ghZ c15111ghZ = new C15111ghZ();
|
||
|
C14957gcv.e(str, "");
|
||
|
C14957gcv.e(charset, "");
|
||
|
C15111ghZ d = c15111ghZ.d(str, 0, str.length(), charset);
|
||
|
return create(d, mediaType, d.c);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ ResponseBody create$default(Companion companion, byte[] bArr, MediaType mediaType, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
mediaType = null;
|
||
|
}
|
||
|
return companion.create(bArr, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(byte[] bArr, MediaType mediaType) {
|
||
|
C14957gcv.e(bArr, "");
|
||
|
C15111ghZ c15111ghZ = new C15111ghZ();
|
||
|
C14957gcv.e(bArr, "");
|
||
|
return create(c15111ghZ.b(bArr, 0, bArr.length), mediaType, bArr.length);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ ResponseBody create$default(Companion companion, C15155gij c15155gij, MediaType mediaType, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
mediaType = null;
|
||
|
}
|
||
|
return companion.create(c15155gij, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(C15155gij c15155gij, MediaType mediaType) {
|
||
|
C14957gcv.e(c15155gij, "");
|
||
|
C15111ghZ c15111ghZ = new C15111ghZ();
|
||
|
C14957gcv.e(c15155gij, "");
|
||
|
c15155gij.a(c15111ghZ, c15155gij.a());
|
||
|
return create(c15111ghZ, mediaType, c15155gij.a());
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ ResponseBody create$default(Companion companion, InterfaceC15149gid interfaceC15149gid, MediaType mediaType, long j, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
mediaType = null;
|
||
|
}
|
||
|
if ((i & 2) != 0) {
|
||
|
j = -1;
|
||
|
}
|
||
|
return companion.create(interfaceC15149gid, mediaType, j);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(final InterfaceC15149gid interfaceC15149gid, final MediaType mediaType, final long j) {
|
||
|
C14957gcv.e(interfaceC15149gid, "");
|
||
|
return new ResponseBody(mediaType, j, interfaceC15149gid) { // from class: okhttp3.ResponseBody$Companion$asResponseBody$1
|
||
|
final long $contentLength;
|
||
|
final MediaType $contentType;
|
||
|
final InterfaceC15149gid $this_asResponseBody;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
{
|
||
|
this.$contentType = mediaType;
|
||
|
this.$contentLength = j;
|
||
|
this.$this_asResponseBody = interfaceC15149gid;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.ResponseBody
|
||
|
public final InterfaceC15149gid source() {
|
||
|
return this.$this_asResponseBody;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.ResponseBody
|
||
|
public final MediaType contentType() {
|
||
|
return this.$contentType;
|
||
|
}
|
||
|
|
||
|
@Override // okhttp3.ResponseBody
|
||
|
public final long contentLength() {
|
||
|
return this.$contentLength;
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(MediaType mediaType, String str) {
|
||
|
C14957gcv.e(str, "");
|
||
|
return create(str, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(MediaType mediaType, byte[] bArr) {
|
||
|
C14957gcv.e(bArr, "");
|
||
|
return create(bArr, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(MediaType mediaType, C15155gij c15155gij) {
|
||
|
C14957gcv.e(c15155gij, "");
|
||
|
return create(c15155gij, mediaType);
|
||
|
}
|
||
|
|
||
|
public final ResponseBody create(MediaType mediaType, long j, InterfaceC15149gid interfaceC15149gid) {
|
||
|
C14957gcv.e(interfaceC15149gid, "");
|
||
|
return create(interfaceC15149gid, mediaType, j);
|
||
|
}
|
||
|
|
||
|
public /* synthetic */ Companion(C14953gcr c14953gcr) {
|
||
|
this();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final byte[] bytes() throws IOException {
|
||
|
long contentLength = contentLength();
|
||
|
if (contentLength > 2147483647L) {
|
||
|
throw new IOException(C14957gcv.c("Cannot buffer entire body for content length: ", Long.valueOf(contentLength)));
|
||
|
}
|
||
|
InterfaceC15149gid source = source();
|
||
|
try {
|
||
|
byte[] k = source.k();
|
||
|
gbF.d(source, null);
|
||
|
int length = k.length;
|
||
|
if (contentLength == -1 || contentLength == length) {
|
||
|
return k;
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder("Content-Length (");
|
||
|
sb.append(contentLength);
|
||
|
sb.append(") and stream length (");
|
||
|
sb.append(length);
|
||
|
sb.append(") disagree");
|
||
|
throw new IOException(sb.toString());
|
||
|
} finally {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final C15155gij byteString() throws IOException {
|
||
|
long contentLength = contentLength();
|
||
|
if (contentLength > 2147483647L) {
|
||
|
throw new IOException(C14957gcv.c("Cannot buffer entire body for content length: ", Long.valueOf(contentLength)));
|
||
|
}
|
||
|
InterfaceC15149gid source = source();
|
||
|
try {
|
||
|
C15155gij l = source.l();
|
||
|
gbF.d(source, null);
|
||
|
int a = l.a();
|
||
|
if (contentLength == -1 || contentLength == a) {
|
||
|
return l;
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder("Content-Length (");
|
||
|
sb.append(contentLength);
|
||
|
sb.append(") and stream length (");
|
||
|
sb.append(a);
|
||
|
sb.append(") disagree");
|
||
|
throw new IOException(sb.toString());
|
||
|
} finally {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(byte[] bArr, MediaType mediaType) {
|
||
|
return Companion.create(bArr, mediaType);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(C15155gij c15155gij, MediaType mediaType) {
|
||
|
return Companion.create(c15155gij, mediaType);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(InterfaceC15149gid interfaceC15149gid, MediaType mediaType, long j) {
|
||
|
return Companion.create(interfaceC15149gid, mediaType, j);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(MediaType mediaType, byte[] bArr) {
|
||
|
return Companion.create(mediaType, bArr);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(MediaType mediaType, C15155gij c15155gij) {
|
||
|
return Companion.create(mediaType, c15155gij);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(MediaType mediaType, String str) {
|
||
|
return Companion.create(mediaType, str);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(MediaType mediaType, long j, InterfaceC15149gid interfaceC15149gid) {
|
||
|
return Companion.create(mediaType, j, interfaceC15149gid);
|
||
|
}
|
||
|
|
||
|
public static final ResponseBody create(String str, MediaType mediaType) {
|
||
|
return Companion.create(str, mediaType);
|
||
|
}
|
||
|
}
|