apk(点击下载) / e.java


package com.meizu.cloud.pushsdk.b.c;

import com.meizu.cloud.pushsdk.b.c.k;
import com.meizu.cloud.pushsdk.b.g.b;
import com.meizu.cloud.pushsdk.b.g.c;
import com.meizu.cloud.pushsdk.b.g.f;
import com.meizu.cloud.pushsdk.b.h.a;
import com.netease.nim.uikit.common.util.sys.TimeUtil;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;

public class e implements a {
    a a = new a(null);

    private static l a(final HttpURLConnection httpURLConnection) throws IOException {
        if (!httpURLConnection.getDoInput()) {
            return null;
        }
        final c a2 = f.a(f.a(a(httpURLConnection.getResponseCode()) ? httpURLConnection.getInputStream() : httpURLConnection.getErrorStream()));
        return new l() {
            /* class com.meizu.cloud.pushsdk.b.c.e.AnonymousClass1 */

            @Override // com.meizu.cloud.pushsdk.b.c.l
            public c a() {
                return a2;
            }
        };
    }

    static void a(HttpURLConnection httpURLConnection, i iVar) throws IOException {
        String str;
        String str2;
        int c = iVar.c();
        if (c != 0) {
            if (c == 1) {
                str2 = "POST";
            } else if (c == 2) {
                str2 = "PUT";
            } else if (c == 3) {
                str = "DELETE";
            } else if (c == 4) {
                str = "HEAD";
            } else if (c == 5) {
                str2 = "PATCH";
            } else {
                throw new IllegalStateException("Unknown method type.");
            }
            httpURLConnection.setRequestMethod(str2);
            b(httpURLConnection, iVar);
            return;
        }
        str = "GET";
        httpURLConnection.setRequestMethod(str);
    }

    protected static boolean a(int i) {
        return i >= 200 && i < 300;
    }

    private HttpURLConnection b(i iVar) throws IOException {
        String fVar = iVar.a().toString();
        HttpURLConnection a2 = a(new URL(fVar));
        a2.setConnectTimeout(TimeUtil.MIN_IN_MS);
        a2.setReadTimeout(TimeUtil.MIN_IN_MS);
        a2.setUseCaches(false);
        a2.setDoInput(true);
        if (iVar.f() && fVar.startsWith("https://api-push.meizu.com")) {
            ((HttpsURLConnection) a2).setSSLSocketFactory(this.a);
        }
        return a2;
    }

    private static void b(HttpURLConnection httpURLConnection, i iVar) throws IOException {
        j e = iVar.e();
        if (e != null) {
            httpURLConnection.setDoOutput(true);
            httpURLConnection.addRequestProperty("Content-Type", e.a().toString());
            b a2 = f.a(f.a(httpURLConnection.getOutputStream()));
            e.a(a2);
            a2.close();
        }
    }

    @Override // com.meizu.cloud.pushsdk.b.c.a
    public k a(i iVar) throws IOException {
        HttpURLConnection b = b(iVar);
        for (String str : iVar.d().b()) {
            String a2 = iVar.a(str);
            com.meizu.cloud.pushsdk.b.a.a.b("current header name " + str + " value " + a2);
            b.addRequestProperty(str, a2);
        }
        a(b, iVar);
        int responseCode = b.getResponseCode();
        return new k.a().a(responseCode).a(iVar.d()).a(b.getResponseMessage()).a(iVar).a(a(b)).a();
    }

    /* access modifiers changed from: protected */
    public HttpURLConnection a(URL url) throws IOException {
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setInstanceFollowRedirects(HttpURLConnection.getFollowRedirects());
        return httpURLConnection;
    }
}