Initial commit
This commit is contained in:
119
sources/okhttp3/FormBody.java
Normal file
119
sources/okhttp3/FormBody.java
Normal file
@@ -0,0 +1,119 @@
|
||||
package okhttp3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okhttp3.internal.Util;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSink;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class FormBody extends RequestBody {
|
||||
private static final MediaType CONTENT_TYPE = MediaType.get("application/x-www-form-urlencoded");
|
||||
private final List<String> encodedNames;
|
||||
private final List<String> encodedValues;
|
||||
|
||||
public static final class Builder {
|
||||
private final Charset charset;
|
||||
private final List<String> names;
|
||||
private final List<String> values;
|
||||
|
||||
public Builder() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public Builder add(String str, String str2) {
|
||||
if (str == null) {
|
||||
throw new NullPointerException("name == null");
|
||||
}
|
||||
if (str2 == null) {
|
||||
throw new NullPointerException("value == null");
|
||||
}
|
||||
this.names.add(HttpUrl.canonicalize(str, " \"':;<=>@[]^`{}|/\\?#&!$(),~", false, false, true, true, this.charset));
|
||||
this.values.add(HttpUrl.canonicalize(str2, " \"':;<=>@[]^`{}|/\\?#&!$(),~", false, false, true, true, this.charset));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addEncoded(String str, String str2) {
|
||||
if (str == null) {
|
||||
throw new NullPointerException("name == null");
|
||||
}
|
||||
if (str2 == null) {
|
||||
throw new NullPointerException("value == null");
|
||||
}
|
||||
this.names.add(HttpUrl.canonicalize(str, " \"':;<=>@[]^`{}|/\\?#&!$(),~", true, false, true, true, this.charset));
|
||||
this.values.add(HttpUrl.canonicalize(str2, " \"':;<=>@[]^`{}|/\\?#&!$(),~", true, false, true, true, this.charset));
|
||||
return this;
|
||||
}
|
||||
|
||||
public FormBody build() {
|
||||
return new FormBody(this.names, this.values);
|
||||
}
|
||||
|
||||
public Builder(Charset charset) {
|
||||
this.names = new ArrayList();
|
||||
this.values = new ArrayList();
|
||||
this.charset = charset;
|
||||
}
|
||||
}
|
||||
|
||||
FormBody(List<String> list, List<String> list2) {
|
||||
this.encodedNames = Util.immutableList(list);
|
||||
this.encodedValues = Util.immutableList(list2);
|
||||
}
|
||||
|
||||
private long writeOrCountBytes(BufferedSink bufferedSink, boolean z) {
|
||||
Buffer buffer = z ? new Buffer() : bufferedSink.buffer();
|
||||
int size = this.encodedNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 0) {
|
||||
buffer.writeByte(38);
|
||||
}
|
||||
buffer.writeUtf8(this.encodedNames.get(i));
|
||||
buffer.writeByte(61);
|
||||
buffer.writeUtf8(this.encodedValues.get(i));
|
||||
}
|
||||
if (!z) {
|
||||
return 0L;
|
||||
}
|
||||
long size2 = buffer.size();
|
||||
buffer.clear();
|
||||
return size2;
|
||||
}
|
||||
|
||||
@Override // okhttp3.RequestBody
|
||||
public long contentLength() {
|
||||
return writeOrCountBytes(null, true);
|
||||
}
|
||||
|
||||
@Override // okhttp3.RequestBody
|
||||
public MediaType contentType() {
|
||||
return CONTENT_TYPE;
|
||||
}
|
||||
|
||||
public String encodedName(int i) {
|
||||
return this.encodedNames.get(i);
|
||||
}
|
||||
|
||||
public String encodedValue(int i) {
|
||||
return this.encodedValues.get(i);
|
||||
}
|
||||
|
||||
public String name(int i) {
|
||||
return HttpUrl.percentDecode(encodedName(i), true);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.encodedNames.size();
|
||||
}
|
||||
|
||||
public String value(int i) {
|
||||
return HttpUrl.percentDecode(encodedValue(i), true);
|
||||
}
|
||||
|
||||
@Override // okhttp3.RequestBody
|
||||
public void writeTo(BufferedSink bufferedSink) throws IOException {
|
||||
writeOrCountBytes(bufferedSink, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user