翰林优商.apk(点击下载) / a.java


package com.efs.sdk.base.core.util.b;

import com.baidu.mobads.sdk.internal.ae;
import com.efs.sdk.base.core.util.Log;
import com.efs.sdk.base.core.util.b;
import com.efs.sdk.base.http.HttpResponse;
import com.efs.sdk.base.http.IHttpUtil;
import com.mbridge.msdk.playercommon.exoplayer2.DefaultLoadControl;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Map;

public final class a implements IHttpUtil {

    /* access modifiers changed from: package-private */
    /* renamed from: com.efs.sdk.base.core.util.b.a$a  reason: collision with other inner class name */
    public static class C0054a {
        private static final a a = new a((byte) 0);
    }

    /* synthetic */ a(byte b) {
        this();
    }

    private a() {
    }

    public static a a() {
        return C0054a.a;
    }

    private static HttpURLConnection a(String str, Map<String, String> map) {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        httpURLConnection.setConnectTimeout(DefaultLoadControl.DEFAULT_MIN_BUFFER_MS);
        httpURLConnection.setReadTimeout(10000);
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setUseCaches(false);
        if (map == null) {
            map = Collections.emptyMap();
        }
        for (Map.Entry<String, String> entry : map.entrySet()) {
            httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
        }
        return httpURLConnection;
    }

    private static HttpResponse a(HttpURLConnection httpURLConnection) {
        InputStream inputStream;
        ByteArrayOutputStream byteArrayOutputStream;
        Throwable th;
        HttpResponse httpResponse = new HttpResponse();
        if (httpURLConnection == null) {
            return httpResponse;
        }
        try {
            httpResponse.setHttpCode(httpURLConnection.getResponseCode());
            inputStream = httpURLConnection.getInputStream();
            try {
                byte[] bArr = new byte[1024];
                byteArrayOutputStream = new ByteArrayOutputStream(inputStream.available());
                while (true) {
                    try {
                        int read = inputStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        byteArrayOutputStream.write(bArr, 0, read);
                    } catch (Throwable th2) {
                        th = th2;
                        try {
                            Log.e("efs.util.http", "get response error", th);
                            b.a(inputStream);
                            b.a(byteArrayOutputStream);
                            return httpResponse;
                        } catch (Throwable th3) {
                            b.a(inputStream);
                            b.a(byteArrayOutputStream);
                            throw th3;
                        }
                    }
                }
                httpResponse.data = byteArrayOutputStream.toString();
            } catch (Throwable th4) {
                byteArrayOutputStream = null;
                th = th4;
                Log.e("efs.util.http", "get response error", th);
                b.a(inputStream);
                b.a(byteArrayOutputStream);
                return httpResponse;
            }
        } catch (Throwable th5) {
            byteArrayOutputStream = null;
            th = th5;
            inputStream = null;
            Log.e("efs.util.http", "get response error", th);
            b.a(inputStream);
            b.a(byteArrayOutputStream);
            return httpResponse;
        }
        b.a(inputStream);
        b.a(byteArrayOutputStream);
        return httpResponse;
    }

    @Override // com.efs.sdk.base.http.IHttpUtil
    public final HttpResponse get(String str, Map<String, String> map) {
        HttpURLConnection httpURLConnection;
        HttpResponse httpResponse = new HttpResponse();
        int i = 0;
        while (true) {
            if (i >= 3) {
                break;
            }
            httpURLConnection = null;
            try {
                httpURLConnection = a(str, map);
                httpURLConnection.setRequestMethod("GET");
                httpURLConnection.setInstanceFollowRedirects(true);
                httpURLConnection.setRequestProperty("Connection", "close");
                httpURLConnection.connect();
                httpResponse = a(httpURLConnection);
                b(httpURLConnection);
                break;
            } catch (UnknownHostException e) {
                httpResponse.setHttpCode(-2);
                Log.e("efs.util.http", "get request '" + str + "' error, maybe network is disconnect", e);
            } catch (SocketTimeoutException e2) {
                httpResponse.setHttpCode(-3);
                Log.e("efs.util.http", "post file '" + str + "' error", e2);
            } catch (Throwable th) {
                b(httpURLConnection);
                throw th;
            }
            b(httpURLConnection);
        }
        httpResponse.setReqUrl(str);
        return httpResponse;
    }

    @Override // com.efs.sdk.base.http.IHttpUtil
    public final HttpResponse postAsFile(String str, Map<String, String> map, byte[] bArr) {
        return a(str, map, null, bArr);
    }

    @Override // com.efs.sdk.base.http.IHttpUtil
    public final HttpResponse post(String str, Map<String, String> map, File file) {
        return a(str, map, file, null);
    }

    private static HttpResponse a(String str, Map<String, String> map, File file, byte[] bArr) {
        FileInputStream fileInputStream;
        UnknownHostException e;
        DataOutputStream dataOutputStream;
        OutputStream outputStream;
        SocketTimeoutException e2;
        Throwable th;
        HttpResponse httpResponse = new HttpResponse();
        HttpURLConnection httpURLConnection = null;
        FileInputStream fileInputStream2 = null;
        httpURLConnection = null;
        httpURLConnection = null;
        try {
            HttpURLConnection a = a(str, map);
            try {
                a.setRequestMethod(ae.b);
                a.setRequestProperty("Connection", "close");
                a.setRequestProperty("Content-Type", "multipart/form-data;boundary=----WebKitFormBoundaryP0Rfzlf32iRoMhmb");
                outputStream = a.getOutputStream();
                try {
                    dataOutputStream = new DataOutputStream(outputStream);
                } catch (UnknownHostException e3) {
                    e = e3;
                    fileInputStream = null;
                    dataOutputStream = null;
                    httpURLConnection = a;
                    httpResponse.setHttpCode(-2);
                    Log.e("efs.util.http", "post file '" + str + "' error, maybe network is disconnect", e);
                    b(httpURLConnection);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream);
                    httpResponse.setReqUrl(str);
                    return httpResponse;
                } catch (SocketTimeoutException e4) {
                    e2 = e4;
                    fileInputStream = null;
                    dataOutputStream = null;
                    httpURLConnection = a;
                    httpResponse.setHttpCode(-3);
                    Log.e("efs.util.http", "post file '" + str + "' error", e2);
                    b(httpURLConnection);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream);
                    httpResponse.setReqUrl(str);
                    return httpResponse;
                } catch (Throwable th2) {
                    th = th2;
                    fileInputStream = null;
                    dataOutputStream = null;
                    httpURLConnection = a;
                    try {
                        Log.e("efs.util.http", "post file '" + str + "' error", th);
                        b(httpURLConnection);
                        b.a(outputStream);
                        b.a(dataOutputStream);
                        b.a(fileInputStream);
                        httpResponse.setReqUrl(str);
                        return httpResponse;
                    } catch (Throwable th3) {
                        b(httpURLConnection);
                        b.a(outputStream);
                        b.a(dataOutputStream);
                        b.a(fileInputStream);
                        throw th3;
                    }
                }
                try {
                    dataOutputStream.writeBytes("------WebKitFormBoundaryP0Rfzlf32iRoMhmb\r\n");
                    if (bArr != null) {
                        dataOutputStream.writeBytes("Content-Disposition: form-data;name=\"file\";filename=\"f\"\r\n");
                        dataOutputStream.writeBytes("\r\n");
                        dataOutputStream.write(bArr, 0, bArr.length);
                    } else if (file == null || !file.exists()) {
                        b(a);
                        b.a(outputStream);
                        b.a(dataOutputStream);
                        b.a((Closeable) null);
                        return httpResponse;
                    } else {
                        dataOutputStream.writeBytes("Content-Disposition: form-data;name=\"file\";filename=\"" + file.getName() + "\"\r\n");
                        dataOutputStream.writeBytes("\r\n");
                        fileInputStream = new FileInputStream(file);
                        try {
                            byte[] bArr2 = new byte[4096];
                            while (true) {
                                int read = fileInputStream.read(bArr2);
                                if (read == -1) {
                                    break;
                                }
                                dataOutputStream.write(bArr2, 0, read);
                            }
                            fileInputStream2 = fileInputStream;
                        } catch (UnknownHostException e5) {
                            e = e5;
                            httpURLConnection = a;
                            httpResponse.setHttpCode(-2);
                            Log.e("efs.util.http", "post file '" + str + "' error, maybe network is disconnect", e);
                            b(httpURLConnection);
                            b.a(outputStream);
                            b.a(dataOutputStream);
                            b.a(fileInputStream);
                            httpResponse.setReqUrl(str);
                            return httpResponse;
                        } catch (SocketTimeoutException e6) {
                            e2 = e6;
                            httpURLConnection = a;
                            httpResponse.setHttpCode(-3);
                            Log.e("efs.util.http", "post file '" + str + "' error", e2);
                            b(httpURLConnection);
                            b.a(outputStream);
                            b.a(dataOutputStream);
                            b.a(fileInputStream);
                            httpResponse.setReqUrl(str);
                            return httpResponse;
                        } catch (Throwable th4) {
                            th = th4;
                            httpURLConnection = a;
                            Log.e("efs.util.http", "post file '" + str + "' error", th);
                            b(httpURLConnection);
                            b.a(outputStream);
                            b.a(dataOutputStream);
                            b.a(fileInputStream);
                            httpResponse.setReqUrl(str);
                            return httpResponse;
                        }
                    }
                    dataOutputStream.writeBytes("\r\n");
                    dataOutputStream.writeBytes("------WebKitFormBoundaryP0Rfzlf32iRoMhmb--\r\n");
                    httpResponse = a(a);
                    b(a);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream2);
                } catch (UnknownHostException e7) {
                    e = e7;
                    fileInputStream = null;
                    httpURLConnection = a;
                    httpResponse.setHttpCode(-2);
                    Log.e("efs.util.http", "post file '" + str + "' error, maybe network is disconnect", e);
                    b(httpURLConnection);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream);
                    httpResponse.setReqUrl(str);
                    return httpResponse;
                } catch (SocketTimeoutException e8) {
                    e2 = e8;
                    fileInputStream = null;
                    httpURLConnection = a;
                    httpResponse.setHttpCode(-3);
                    Log.e("efs.util.http", "post file '" + str + "' error", e2);
                    b(httpURLConnection);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream);
                    httpResponse.setReqUrl(str);
                    return httpResponse;
                } catch (Throwable th5) {
                    th = th5;
                    fileInputStream = null;
                    httpURLConnection = a;
                    Log.e("efs.util.http", "post file '" + str + "' error", th);
                    b(httpURLConnection);
                    b.a(outputStream);
                    b.a(dataOutputStream);
                    b.a(fileInputStream);
                    httpResponse.setReqUrl(str);
                    return httpResponse;
                }
            } catch (UnknownHostException e9) {
                e = e9;
                fileInputStream = null;
                outputStream = null;
                dataOutputStream = null;
                httpURLConnection = a;
                httpResponse.setHttpCode(-2);
                Log.e("efs.util.http", "post file '" + str + "' error, maybe network is disconnect", e);
                b(httpURLConnection);
                b.a(outputStream);
                b.a(dataOutputStream);
                b.a(fileInputStream);
                httpResponse.setReqUrl(str);
                return httpResponse;
            } catch (SocketTimeoutException e10) {
                e2 = e10;
                fileInputStream = null;
                outputStream = null;
                dataOutputStream = null;
                httpURLConnection = a;
                httpResponse.setHttpCode(-3);
                Log.e("efs.util.http", "post file '" + str + "' error", e2);
                b(httpURLConnection);
                b.a(outputStream);
                b.a(dataOutputStream);
                b.a(fileInputStream);
                httpResponse.setReqUrl(str);
                return httpResponse;
            } catch (Throwable th6) {
                th = th6;
                fileInputStream = null;
                outputStream = null;
                dataOutputStream = null;
                httpURLConnection = a;
                Log.e("efs.util.http", "post file '" + str + "' error", th);
                b(httpURLConnection);
                b.a(outputStream);
                b.a(dataOutputStream);
                b.a(fileInputStream);
                httpResponse.setReqUrl(str);
                return httpResponse;
            }
        } catch (UnknownHostException e11) {
            e = e11;
            fileInputStream = null;
            outputStream = null;
            dataOutputStream = null;
            httpResponse.setHttpCode(-2);
            Log.e("efs.util.http", "post file '" + str + "' error, maybe network is disconnect", e);
            b(httpURLConnection);
            b.a(outputStream);
            b.a(dataOutputStream);
            b.a(fileInputStream);
            httpResponse.setReqUrl(str);
            return httpResponse;
        } catch (SocketTimeoutException e12) {
            e2 = e12;
            fileInputStream = null;
            outputStream = null;
            dataOutputStream = null;
            httpResponse.setHttpCode(-3);
            Log.e("efs.util.http", "post file '" + str + "' error", e2);
            b(httpURLConnection);
            b.a(outputStream);
            b.a(dataOutputStream);
            b.a(fileInputStream);
            httpResponse.setReqUrl(str);
            return httpResponse;
        } catch (Throwable th7) {
            th = th7;
            fileInputStream = null;
            outputStream = null;
            dataOutputStream = null;
            Log.e("efs.util.http", "post file '" + str + "' error", th);
            b(httpURLConnection);
            b.a(outputStream);
            b.a(dataOutputStream);
            b.a(fileInputStream);
            httpResponse.setReqUrl(str);
            return httpResponse;
        }
        httpResponse.setReqUrl(str);
        return httpResponse;
    }

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:1:0x000a */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r8v0, types: [java.util.Map<java.lang.String, java.lang.String>, java.util.Map] */
    /* JADX WARN: Type inference failed for: r8v1, types: [java.net.HttpURLConnection] */
    /* JADX WARN: Type inference failed for: r8v6 */
    /* JADX WARN: Type inference failed for: r8v7 */
    /* JADX WARN: Type inference failed for: r8v14 */
    @Override // com.efs.sdk.base.http.IHttpUtil
    public final HttpResponse post(String str, Map<String, String> map, byte[] bArr) {
        UnknownHostException e;
        HttpURLConnection httpURLConnection;
        SocketTimeoutException e2;
        HttpURLConnection httpURLConnection2;
        Throwable th;
        HttpURLConnection httpURLConnection3;
        HttpResponse httpResponse = new HttpResponse();
        OutputStream outputStream = null;
        try {
            HttpURLConnection a = a(str, map);
            try {
                a.setRequestMethod(ae.b);
                a.setRequestProperty("Connection", "close");
                outputStream = a.getOutputStream();
                outputStream.write(bArr);
                httpResponse = a(a);
                httpURLConnection3 = a;
            } catch (UnknownHostException e3) {
                e = e3;
                httpURLConnection = a;
                httpResponse.setHttpCode(-2);
                Log.e("efs.util.http", "post data to '" + str + "' error, maybe network is disconnect", e);
                httpURLConnection3 = httpURLConnection;
                b.a(outputStream);
                b(httpURLConnection3);
                httpResponse.setReqUrl(str);
                return httpResponse;
            } catch (SocketTimeoutException e4) {
                e2 = e4;
                httpURLConnection2 = a;
                httpResponse.setHttpCode(-3);
                Log.e("efs.util.http", "post file '" + str + "' error", e2);
                httpURLConnection3 = httpURLConnection2;
                b.a(outputStream);
                b(httpURLConnection3);
                httpResponse.setReqUrl(str);
                return httpResponse;
            } catch (Throwable th2) {
                th = th2;
                map = a;
                Log.e("efs.util.http", "post data '" + str + "' error", th);
                httpURLConnection3 = map;
                b.a(outputStream);
                b(httpURLConnection3);
                httpResponse.setReqUrl(str);
                return httpResponse;
            }
        } catch (UnknownHostException e5) {
            e = e5;
            httpURLConnection = null;
            httpResponse.setHttpCode(-2);
            Log.e("efs.util.http", "post data to '" + str + "' error, maybe network is disconnect", e);
            httpURLConnection3 = httpURLConnection;
            b.a(outputStream);
            b(httpURLConnection3);
            httpResponse.setReqUrl(str);
            return httpResponse;
        } catch (SocketTimeoutException e6) {
            e2 = e6;
            httpURLConnection2 = null;
            httpResponse.setHttpCode(-3);
            Log.e("efs.util.http", "post file '" + str + "' error", e2);
            httpURLConnection3 = httpURLConnection2;
            b.a(outputStream);
            b(httpURLConnection3);
            httpResponse.setReqUrl(str);
            return httpResponse;
        } catch (Throwable th3) {
            b.a(outputStream);
            b(map);
            throw th3;
        }
        b.a(outputStream);
        b(httpURLConnection3);
        httpResponse.setReqUrl(str);
        return httpResponse;
    }

    private static void b(HttpURLConnection httpURLConnection) {
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
            try {
                b.a(httpURLConnection.getInputStream());
            } catch (Throwable unused) {
            }
        }
    }
}