what-the-bank/sources/okhttp3/repackaged/RequestBody.java

136 lines
4.2 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import o.C15145giV;
import o.giO;
import o.giP;
import o.giZ;
import okhttp3.repackaged.internal.Util;
/* loaded from: classes6.dex */
public abstract class RequestBody {
public long contentLength() throws IOException {
return -1L;
}
public abstract MediaType contentType();
public abstract void writeTo(giO gio) throws IOException;
public static RequestBody create(MediaType mediaType, String str) {
Charset charset = Util.UTF_8;
if (mediaType != null && (charset = mediaType.charset()) == null) {
charset = Util.UTF_8;
StringBuilder sb = new StringBuilder();
sb.append(mediaType);
sb.append("; charset=utf-8");
mediaType = MediaType.parse(sb.toString());
}
return create(mediaType, str.getBytes(charset));
}
public static RequestBody create(MediaType mediaType, giP gip) {
return new RequestBody(mediaType, gip) { // from class: okhttp3.repackaged.RequestBody.1
final MediaType aiD;
final giP aiE;
{
this.aiD = mediaType;
this.aiE = gip;
}
@Override // okhttp3.repackaged.RequestBody
public final long contentLength() throws IOException {
return this.aiE.d.length;
}
@Override // okhttp3.repackaged.RequestBody
public final void writeTo(giO gio) throws IOException {
gio.e(this.aiE);
}
@Override // okhttp3.repackaged.RequestBody
public final MediaType contentType() {
return this.aiD;
}
};
}
public static RequestBody create(MediaType mediaType, byte[] bArr) {
return create(mediaType, bArr, 0, bArr.length);
}
public static RequestBody create(MediaType mediaType, byte[] bArr, int i, int i2) {
if (bArr == null) {
throw new NullPointerException("content == null");
}
Util.checkOffsetAndCount(bArr.length, i, i2);
return new RequestBody(mediaType, i2, bArr, i) { // from class: okhttp3.repackaged.RequestBody.2
final MediaType aiD;
final int val$byteCount;
final byte[] val$content;
final int val$offset;
{
this.aiD = mediaType;
this.val$byteCount = i2;
this.val$content = bArr;
this.val$offset = i;
}
@Override // okhttp3.repackaged.RequestBody
public final void writeTo(giO gio) throws IOException {
gio.a(this.val$content, this.val$offset, this.val$byteCount);
}
@Override // okhttp3.repackaged.RequestBody
public final MediaType contentType() {
return this.aiD;
}
@Override // okhttp3.repackaged.RequestBody
public final long contentLength() {
return this.val$byteCount;
}
};
}
public static RequestBody create(MediaType mediaType, File file) {
if (file == null) {
throw new NullPointerException("content == null");
}
return new RequestBody(mediaType, file) { // from class: okhttp3.repackaged.RequestBody.3
final MediaType aiD;
final File val$file;
{
this.aiD = mediaType;
this.val$file = file;
}
@Override // okhttp3.repackaged.RequestBody
public final long contentLength() {
return this.val$file.length();
}
@Override // okhttp3.repackaged.RequestBody
public final void writeTo(giO gio) throws IOException {
giZ giz = null;
try {
giz = C15145giV.d(this.val$file);
gio.d(giz);
} finally {
Util.closeQuietly(giz);
}
}
@Override // okhttp3.repackaged.RequestBody
public final MediaType contentType() {
return this.aiD;
}
};
}
}