what-the-bank/sources/retrofit2/ParameterHandler.java

509 lines
20 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package retrofit2;
import com.google.common.net.HttpHeaders;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public abstract class ParameterHandler<T> {
/* JADX INFO: Access modifiers changed from: package-private */
public abstract void apply(RequestBuilder requestBuilder, T t) throws IOException;
ParameterHandler() {
}
/* JADX INFO: Access modifiers changed from: package-private */
public final ParameterHandler<Iterable<T>> iterable() {
return new ParameterHandler<Iterable<T>>(this) { // from class: retrofit2.ParameterHandler.1
final ParameterHandler this$0;
{
this.this$0 = this;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public void apply(RequestBuilder requestBuilder, Iterable<T> iterable) throws IOException {
if (iterable == null) {
return;
}
Iterator<T> it = iterable.iterator();
while (it.hasNext()) {
this.this$0.apply(requestBuilder, it.next());
}
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
public final ParameterHandler<Object> array() {
return new ParameterHandler<Object>(this) { // from class: retrofit2.ParameterHandler.2
final ParameterHandler this$0;
{
this.this$0 = this;
}
/* JADX WARN: Multi-variable type inference failed */
@Override // retrofit2.ParameterHandler
void apply(RequestBuilder requestBuilder, Object obj) throws IOException {
if (obj == null) {
return;
}
int length = Array.getLength(obj);
for (int i = 0; i < length; i++) {
this.this$0.apply(requestBuilder, Array.get(obj, i));
}
}
};
}
/* loaded from: classes.dex */
static final class RelativeUrl extends ParameterHandler<Object> {
private final Method method;
private final int p;
/* JADX INFO: Access modifiers changed from: package-private */
public RelativeUrl(Method method, int i) {
this.method = method;
this.p = i;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, Object obj) {
if (obj == null) {
throw Utils.parameterError(this.method, this.p, "@Url parameter is null.", new Object[0]);
}
requestBuilder.setRelativeUrl(obj);
}
}
/* loaded from: classes.dex */
static final class Header<T> extends ParameterHandler<T> {
private final String name;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public Header(String str, Converter<T, String> converter) {
this.name = (String) Objects.requireNonNull(str, "name == null");
this.valueConverter = converter;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) throws IOException {
String convert;
if (t == null || (convert = this.valueConverter.convert(t)) == null) {
return;
}
requestBuilder.addHeader(this.name, convert);
}
}
/* loaded from: classes.dex */
static final class Path<T> extends ParameterHandler<T> {
private final boolean encoded;
private final Method method;
private final String name;
private final int p;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public Path(Method method, int i, String str, Converter<T, String> converter, boolean z) {
this.method = method;
this.p = i;
this.name = (String) Objects.requireNonNull(str, "name == null");
this.valueConverter = converter;
this.encoded = z;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) throws IOException {
if (t == null) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Path parameter \"");
sb.append(this.name);
sb.append("\" value must not be null.");
throw Utils.parameterError(method, i, sb.toString(), new Object[0]);
}
requestBuilder.addPathParam(this.name, this.valueConverter.convert(t), this.encoded);
}
}
/* loaded from: classes.dex */
static final class Query<T> extends ParameterHandler<T> {
private final boolean encoded;
private final String name;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public Query(String str, Converter<T, String> converter, boolean z) {
this.name = (String) Objects.requireNonNull(str, "name == null");
this.valueConverter = converter;
this.encoded = z;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) throws IOException {
String convert;
if (t == null || (convert = this.valueConverter.convert(t)) == null) {
return;
}
requestBuilder.addQueryParam(this.name, convert, this.encoded);
}
}
/* loaded from: classes.dex */
static final class QueryName<T> extends ParameterHandler<T> {
private final boolean encoded;
private final Converter<T, String> nameConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public QueryName(Converter<T, String> converter, boolean z) {
this.nameConverter = converter;
this.encoded = z;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) throws IOException {
if (t == null) {
return;
}
requestBuilder.addQueryParam(this.nameConverter.convert(t), null, this.encoded);
}
}
/* loaded from: classes.dex */
static final class QueryMap<T> extends ParameterHandler<Map<String, T>> {
private final boolean encoded;
private final Method method;
private final int p;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public QueryMap(Method method, int i, Converter<T, String> converter, boolean z) {
this.method = method;
this.p = i;
this.valueConverter = converter;
this.encoded = z;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, Map<String, T> map) throws IOException {
if (map == null) {
throw Utils.parameterError(this.method, this.p, "Query map was null", new Object[0]);
}
for (Map.Entry<String, T> entry : map.entrySet()) {
String key = entry.getKey();
if (key == null) {
throw Utils.parameterError(this.method, this.p, "Query map contained null key.", new Object[0]);
}
T value = entry.getValue();
if (value == null) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Query map contained null value for key '");
sb.append(key);
sb.append("'.");
throw Utils.parameterError(method, i, sb.toString(), new Object[0]);
}
String convert = this.valueConverter.convert(value);
if (convert == null) {
Method method2 = this.method;
int i2 = this.p;
StringBuilder sb2 = new StringBuilder("Query map value '");
sb2.append(value);
sb2.append("' converted to null by ");
sb2.append(this.valueConverter.getClass().getName());
sb2.append(" for key '");
sb2.append(key);
sb2.append("'.");
throw Utils.parameterError(method2, i2, sb2.toString(), new Object[0]);
}
requestBuilder.addQueryParam(key, convert, this.encoded);
}
}
}
/* loaded from: classes.dex */
static final class HeaderMap<T> extends ParameterHandler<Map<String, T>> {
private final Method method;
private final int p;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public HeaderMap(Method method, int i, Converter<T, String> converter) {
this.method = method;
this.p = i;
this.valueConverter = converter;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, Map<String, T> map) throws IOException {
if (map == null) {
throw Utils.parameterError(this.method, this.p, "Header map was null.", new Object[0]);
}
for (Map.Entry<String, T> entry : map.entrySet()) {
String key = entry.getKey();
if (key == null) {
throw Utils.parameterError(this.method, this.p, "Header map contained null key.", new Object[0]);
}
T value = entry.getValue();
if (value == null) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Header map contained null value for key '");
sb.append(key);
sb.append("'.");
throw Utils.parameterError(method, i, sb.toString(), new Object[0]);
}
requestBuilder.addHeader(key, this.valueConverter.convert(value));
}
}
}
/* loaded from: classes.dex */
static final class Headers extends ParameterHandler<okhttp3.Headers> {
private final Method method;
private final int p;
/* JADX INFO: Access modifiers changed from: package-private */
public Headers(Method method, int i) {
this.method = method;
this.p = i;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, okhttp3.Headers headers) {
if (headers == null) {
throw Utils.parameterError(this.method, this.p, "Headers parameter must not be null.", new Object[0]);
}
requestBuilder.addHeaders(headers);
}
}
/* loaded from: classes.dex */
static final class Field<T> extends ParameterHandler<T> {
private final boolean encoded;
private final String name;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public Field(String str, Converter<T, String> converter, boolean z) {
this.name = (String) Objects.requireNonNull(str, "name == null");
this.valueConverter = converter;
this.encoded = z;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) throws IOException {
String convert;
if (t == null || (convert = this.valueConverter.convert(t)) == null) {
return;
}
requestBuilder.addFormField(this.name, convert, this.encoded);
}
}
/* loaded from: classes.dex */
static final class FieldMap<T> extends ParameterHandler<Map<String, T>> {
private final boolean encoded;
private final Method method;
private final int p;
private final Converter<T, String> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public FieldMap(Method method, int i, Converter<T, String> converter, boolean z) {
this.method = method;
this.p = i;
this.valueConverter = converter;
this.encoded = z;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, Map<String, T> map) throws IOException {
if (map == null) {
throw Utils.parameterError(this.method, this.p, "Field map was null.", new Object[0]);
}
for (Map.Entry<String, T> entry : map.entrySet()) {
String key = entry.getKey();
if (key == null) {
throw Utils.parameterError(this.method, this.p, "Field map contained null key.", new Object[0]);
}
T value = entry.getValue();
if (value == null) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Field map contained null value for key '");
sb.append(key);
sb.append("'.");
throw Utils.parameterError(method, i, sb.toString(), new Object[0]);
}
String convert = this.valueConverter.convert(value);
if (convert == null) {
Method method2 = this.method;
int i2 = this.p;
StringBuilder sb2 = new StringBuilder("Field map value '");
sb2.append(value);
sb2.append("' converted to null by ");
sb2.append(this.valueConverter.getClass().getName());
sb2.append(" for key '");
sb2.append(key);
sb2.append("'.");
throw Utils.parameterError(method2, i2, sb2.toString(), new Object[0]);
}
requestBuilder.addFormField(key, convert, this.encoded);
}
}
}
/* loaded from: classes.dex */
static final class Part<T> extends ParameterHandler<T> {
private final Converter<T, RequestBody> converter;
private final okhttp3.Headers headers;
private final Method method;
private final int p;
/* JADX INFO: Access modifiers changed from: package-private */
public Part(Method method, int i, okhttp3.Headers headers, Converter<T, RequestBody> converter) {
this.method = method;
this.p = i;
this.headers = headers;
this.converter = converter;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) {
if (t == null) {
return;
}
try {
requestBuilder.addPart(this.headers, this.converter.convert(t));
} catch (IOException e) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Unable to convert ");
sb.append(t);
sb.append(" to RequestBody");
throw Utils.parameterError(method, i, sb.toString(), e);
}
}
}
/* loaded from: classes.dex */
static final class RawPart extends ParameterHandler<MultipartBody.Part> {
static final RawPart INSTANCE = new RawPart();
private RawPart() {
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, MultipartBody.Part part) {
if (part != null) {
requestBuilder.addPart(part);
}
}
}
/* loaded from: classes.dex */
static final class PartMap<T> extends ParameterHandler<Map<String, T>> {
private final Method method;
private final int p;
private final String transferEncoding;
private final Converter<T, RequestBody> valueConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public PartMap(Method method, int i, Converter<T, RequestBody> converter, String str) {
this.method = method;
this.p = i;
this.valueConverter = converter;
this.transferEncoding = str;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // retrofit2.ParameterHandler
public final void apply(RequestBuilder requestBuilder, Map<String, T> map) throws IOException {
if (map == null) {
throw Utils.parameterError(this.method, this.p, "Part map was null.", new Object[0]);
}
for (Map.Entry<String, T> entry : map.entrySet()) {
String key = entry.getKey();
if (key == null) {
throw Utils.parameterError(this.method, this.p, "Part map contained null key.", new Object[0]);
}
T value = entry.getValue();
if (value == null) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Part map contained null value for key '");
sb.append(key);
sb.append("'.");
throw Utils.parameterError(method, i, sb.toString(), new Object[0]);
}
StringBuilder sb2 = new StringBuilder("form-data; name=\"");
sb2.append(key);
sb2.append("\"");
requestBuilder.addPart(okhttp3.Headers.of(HttpHeaders.CONTENT_DISPOSITION, sb2.toString(), "Content-Transfer-Encoding", this.transferEncoding), this.valueConverter.convert(value));
}
}
}
/* loaded from: classes.dex */
static final class Body<T> extends ParameterHandler<T> {
private final Converter<T, RequestBody> converter;
private final Method method;
private final int p;
/* JADX INFO: Access modifiers changed from: package-private */
public Body(Method method, int i, Converter<T, RequestBody> converter) {
this.method = method;
this.p = i;
this.converter = converter;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) {
if (t == null) {
throw Utils.parameterError(this.method, this.p, "Body parameter value must not be null.", new Object[0]);
}
try {
requestBuilder.setBody(this.converter.convert(t));
} catch (IOException e) {
Method method = this.method;
int i = this.p;
StringBuilder sb = new StringBuilder("Unable to convert ");
sb.append(t);
sb.append(" to RequestBody");
throw Utils.parameterError(method, e, i, sb.toString(), new Object[0]);
}
}
}
/* loaded from: classes.dex */
static final class Tag<T> extends ParameterHandler<T> {
final Class<T> cls;
/* JADX INFO: Access modifiers changed from: package-private */
public Tag(Class<T> cls) {
this.cls = cls;
}
@Override // retrofit2.ParameterHandler
final void apply(RequestBuilder requestBuilder, T t) {
requestBuilder.addTag(this.cls, t);
}
}
}