Files
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

177 lines
5.7 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 java.nio.charset.StandardCharsets;
import okhttp3.internal.Util;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
/* loaded from: classes5.dex */
public abstract class ResponseBody implements Closeable {
private Reader reader;
public abstract long contentLength();
public abstract MediaType contentType();
public abstract BufferedSource source();
public final InputStream byteStream() {
return source().inputStream();
}
public final byte[] bytes() throws IOException {
long contentLength = contentLength();
if (contentLength > 2147483647L) {
throw new IOException("Cannot buffer entire body for content length: " + contentLength);
}
BufferedSource source = source();
try {
byte[] readByteArray = source.readByteArray();
$closeResource(null, source);
if (contentLength == -1 || contentLength == readByteArray.length) {
return readByteArray;
}
throw new IOException("Content-Length (" + contentLength + ") and stream length (" + readByteArray.length + ") disagree");
} finally {
}
}
public static /* synthetic */ void $closeResource(Throwable th, AutoCloseable autoCloseable) {
if (th == null) {
autoCloseable.close();
return;
}
try {
autoCloseable.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
}
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 {
BufferedSource source = source();
try {
String readString = source.readString(Util.bomAwareCharset(source, charset()));
$closeResource(null, source);
return readString;
} catch (Throwable th) {
try {
throw th;
} catch (Throwable th2) {
if (source != null) {
$closeResource(th, source);
}
throw th2;
}
}
}
public final Charset charset() {
MediaType contentType = contentType();
return contentType != null ? contentType.charset(StandardCharsets.UTF_8) : StandardCharsets.UTF_8;
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() {
Util.closeQuietly(source());
}
public static ResponseBody create(MediaType mediaType, String str) {
Charset charset = StandardCharsets.UTF_8;
if (mediaType != null) {
Charset charset2 = mediaType.charset();
if (charset2 == null) {
mediaType = MediaType.parse(mediaType + "; charset=utf-8");
} else {
charset = charset2;
}
}
Buffer writeString = new Buffer().writeString(str, charset);
return create(mediaType, writeString.size(), writeString);
}
public static ResponseBody create(MediaType mediaType, byte[] bArr) {
return create(mediaType, bArr.length, new Buffer().write(bArr));
}
public static ResponseBody create(MediaType mediaType, ByteString byteString) {
return create(mediaType, byteString.size(), new Buffer().write(byteString));
}
public static ResponseBody create(final MediaType mediaType, final long j, final BufferedSource bufferedSource) {
if (bufferedSource == null) {
throw new NullPointerException("source == null");
}
return new ResponseBody() { // from class: okhttp3.ResponseBody.1
@Override // okhttp3.ResponseBody
public long contentLength() {
return j;
}
@Override // okhttp3.ResponseBody
public MediaType contentType() {
return MediaType.this;
}
@Override // okhttp3.ResponseBody
public BufferedSource source() {
return bufferedSource;
}
};
}
public static final class BomAwareReader extends Reader {
public final Charset charset;
public boolean closed;
public Reader delegate;
public final BufferedSource source;
public BomAwareReader(BufferedSource bufferedSource, Charset charset) {
this.source = bufferedSource;
this.charset = charset;
}
@Override // java.io.Reader
public int read(char[] cArr, int i, int i2) {
if (this.closed) {
throw new IOException("Stream closed");
}
Reader reader = this.delegate;
if (reader == null) {
InputStreamReader inputStreamReader = new InputStreamReader(this.source.inputStream(), Util.bomAwareCharset(this.source, this.charset));
this.delegate = inputStreamReader;
reader = inputStreamReader;
}
return reader.read(cArr, i, i2);
}
@Override // java.io.Reader, java.io.Closeable, java.lang.AutoCloseable
public void close() {
this.closed = true;
Reader reader = this.delegate;
if (reader != null) {
reader.close();
} else {
this.source.close();
}
}
}
}