75 lines
2.7 KiB
Java
75 lines
2.7 KiB
Java
package com.alibaba.sdk.android.oss.internal;
|
|
|
|
import com.alibaba.sdk.android.oss.common.OSSLog;
|
|
import com.alibaba.sdk.android.oss.common.utils.CaseInsensitiveHashMap;
|
|
import com.alibaba.sdk.android.oss.model.OSSResult;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.lang.reflect.ParameterizedType;
|
|
import java.math.BigInteger;
|
|
import java.util.zip.CheckedInputStream;
|
|
import okhttp3.Headers;
|
|
import okhttp3.Response;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class AbstractResponseParser<T extends OSSResult> implements ResponseParser {
|
|
public static void b(ResponseMessage responseMessage) {
|
|
try {
|
|
responseMessage.a();
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
|
|
@Override // com.alibaba.sdk.android.oss.internal.ResponseParser
|
|
public T a(ResponseMessage responseMessage) throws IOException {
|
|
try {
|
|
try {
|
|
T t = (T) ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
|
|
if (t != null) {
|
|
t.a(responseMessage.d().get("x-oss-request-id"));
|
|
t.a(responseMessage.h());
|
|
t.a(a(responseMessage.g()));
|
|
a((AbstractResponseParser<T>) t, responseMessage);
|
|
t = a(responseMessage, (ResponseMessage) t);
|
|
}
|
|
return t;
|
|
} catch (Exception e) {
|
|
IOException iOException = new IOException(e.getMessage(), e);
|
|
e.printStackTrace();
|
|
OSSLog.a(e);
|
|
throw iOException;
|
|
}
|
|
} finally {
|
|
if (a()) {
|
|
b(responseMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
abstract T a(ResponseMessage responseMessage, T t) throws Exception;
|
|
|
|
public boolean a() {
|
|
return true;
|
|
}
|
|
|
|
private CaseInsensitiveHashMap<String, String> a(Response response) {
|
|
CaseInsensitiveHashMap<String, String> caseInsensitiveHashMap = new CaseInsensitiveHashMap<>();
|
|
Headers headers = response.headers();
|
|
for (int i = 0; i < headers.size(); i++) {
|
|
caseInsensitiveHashMap.put(headers.name(i), headers.value(i));
|
|
}
|
|
return caseInsensitiveHashMap;
|
|
}
|
|
|
|
public <Result extends OSSResult> void a(Result result, ResponseMessage responseMessage) {
|
|
InputStream b = responseMessage.f().b();
|
|
if (b != null && (b instanceof CheckedInputStream)) {
|
|
result.a(Long.valueOf(((CheckedInputStream) b).getChecksum().getValue()));
|
|
}
|
|
String str = responseMessage.d().get("x-oss-hash-crc64ecma");
|
|
if (str != null) {
|
|
result.b(Long.valueOf(new BigInteger(str).longValue()));
|
|
}
|
|
}
|
|
}
|