package epson.common.httpclient;

import epson.print.CommonDefine;
import epson.print.Util.EPLog;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;

public class IAHttpClient {
    private static final String CONTENT_ENCODING = "Content-Encoding";
    private static final String CONTENT_LENGTH = "Content-Length";
    private static final String CONTENT_TYPE = "Content-Type";
    private static final String REQUEST_GET = "GET";
    private static final String REQUEST_POST = "POST";
    private static final String TAG = "IAHttpClient";
    private static final String TRANSFER_ENCODING = "Transfer-Encoding";
    private final int BUFFER_SIZE = 1024;
    HttpURLConnection conn = null;
    private Object connLockObj = new Object();
    private int connectionTimeout = 30000;
    private boolean followRedirects = true;
    private int readTimeout = 30000;

    public interface HttpStatus {
        public static final int SC_ACCEPTED = 202;
        public static final int SC_BAD_GATEWAY = 502;
        public static final int SC_BAD_REQUEST = 400;
        public static final int SC_CONFLICT = 409;
        public static final int SC_CONTINUE = 100;
        public static final int SC_CREATED = 201;
        public static final int SC_EXPECTATION_FAILED = 417;
        public static final int SC_FAILED_DEPENDENCY = 424;
        public static final int SC_FORBIDDEN = 403;
        public static final int SC_GATEWAY_TIMEOUT = 504;
        public static final int SC_GONE = 410;
        public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
        public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
        public static final int SC_INSUFFICIENT_STORAGE = 507;
        public static final int SC_INTERNAL_SERVER_ERROR = 500;
        public static final int SC_LENGTH_REQUIRED = 411;
        public static final int SC_LOCKED = 423;
        public static final int SC_METHOD_FAILURE = 420;
        public static final int SC_METHOD_NOT_ALLOWED = 405;
        public static final int SC_MOVED_PERMANENTLY = 301;
        public static final int SC_MOVED_TEMPORARILY = 302;
        public static final int SC_MULTIPLE_CHOICES = 300;
        public static final int SC_MULTI_STATUS = 207;
        public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
        public static final int SC_NOT_ACCEPTABLE = 406;
        public static final int SC_NOT_FOUND = 404;
        public static final int SC_NOT_IMPLEMENTED = 501;
        public static final int SC_NOT_MODIFIED = 304;
        public static final int SC_NO_CONTENT = 204;
        public static final int SC_OK = 200;
        public static final int SC_PARTIAL_CONTENT = 206;
        public static final int SC_PAYMENT_REQUIRED = 402;
        public static final int SC_PRECONDITION_FAILED = 412;
        public static final int SC_PROCESSING = 102;
        public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
        public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
        public static final int SC_REQUEST_TIMEOUT = 408;
        public static final int SC_REQUEST_TOO_LONG = 413;
        public static final int SC_REQUEST_URI_TOO_LONG = 414;
        public static final int SC_RESET_CONTENT = 205;
        public static final int SC_SEE_OTHER = 303;
        public static final int SC_SERVICE_UNAVAILABLE = 503;
        public static final int SC_SWITCHING_PROTOCOLS = 101;
        public static final int SC_TEMPORARY_REDIRECT = 307;
        public static final int SC_UNAUTHORIZED = 401;
        public static final int SC_UNPROCESSABLE_ENTITY = 422;
        public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
        public static final int SC_USE_PROXY = 305;
    }

    public void setConnectionTimeout(int i) {
        connectionTimeout = i;
    }

    public void setSoTimeout(int i) {
        readTimeout = i;
    }

    public void setFollowRedirects(boolean z) {
        followRedirects = z;
    }

    private HttpURLConnection connect(HttpBase httpBase) throws IOException {
        HttpURLConnection httpURLConnection;
        synchronized (this.connLockObj) {
            conn = (HttpURLConnection) httpBase.getURI().openConnection();
            conn.setConnectTimeout(this.connectionTimeout);
            conn.setReadTimeout(this.readTimeout);
            conn.setInstanceFollowRedirects(this.followRedirects);
            httpURLConnection = conn;
        }
        return httpURLConnection;
    }

    public void disconnect() {
        synchronized (this.connLockObj) {
            if (this.conn != null) {
                conn.disconnect();
            }
        }
    }

    public synchronized HttpResponse execute(HttpGet httpGet) throws IOException {
        HttpResponse parseResponse;
        new HttpResponse();
        try {
            conn = connect(httpGet);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            makeHeader(this.conn, httpGet);
            conn.connect();
            parseResponse = parseResponse(this.conn, true);
            disconnect();
        } catch (IOException e) {
            throw e;
        } catch (Throwable th) {
            disconnect();
            throw th;
        }
        return parseResponse;
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(13:1|2|3|4|5|6|7|8|9|10|11|12|13) */
    /* JADX WARNING: Can't wrap try/catch for region: R(5:15|19|20|21|22) */
    /* JADX WARNING: Missing exception handler attribute for start block: B:21:0x0052 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0040 */
    /* JADX WARNING: Unknown top exception splitter block from list: {B:9:0x0040=Splitter:B:9:0x0040, B:21:0x0052=Splitter:B:21:0x0052} */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public synchronized epson.common.httpclient.IAHttpClient.HttpResponse execute(epson.common.httpclient.IAHttpClient.HttpPost r4) throws java.io.IOException {
        /*
            r3 = this;
            monitor-enter(r3)
            epson.common.httpclient.IAHttpClient$HttpResponse r0 = new epson.common.httpclient.IAHttpClient$HttpResponse     // Catch:{ all -> 0x005b }
            r0.<init>()     // Catch:{ all -> 0x005b }
            java.net.HttpURLConnection r0 = r3.connect(r4)     // Catch:{ IOException -> 0x0055 }
            r3.conn = r0     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r0 = r3.conn     // Catch:{ IOException -> 0x0055 }
            java.lang.String r1 = "POST"
            r0.setRequestMethod(r1)     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r0 = r3.conn     // Catch:{ IOException -> 0x0055 }
            r1 = 1
            r0.setDoInput(r1)     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r0 = r3.conn     // Catch:{ IOException -> 0x0055 }
            r0.setDoOutput(r1)     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r0 = r3.conn     // Catch:{ IOException -> 0x0055 }
            r3.makeHeader(r0, r4)     // Catch:{ IOException -> 0x0055 }
            java.io.DataOutputStream r0 = new java.io.DataOutputStream     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r2 = r3.conn     // Catch:{ IOException -> 0x0055 }
            java.io.OutputStream r2 = r2.getOutputStream()     // Catch:{ IOException -> 0x0055 }
            r0.<init>(r2)     // Catch:{ IOException -> 0x0055 }
            java.net.HttpURLConnection r2 = r3.conn     // Catch:{ IOException -> 0x004d }
            r2.connect()     // Catch:{ IOException -> 0x004d }
            java.io.ByteArrayOutputStream r4 = r4.getEntity()     // Catch:{ IOException -> 0x004d }
            r4.writeTo(r0)     // Catch:{ IOException -> 0x004d }
            r0.flush()     // Catch:{ IOException -> 0x004d }
            r0.close()     // Catch:{ IOException -> 0x0040 }
        L_0x0040:
            java.net.HttpURLConnection r4 = r3.conn     // Catch:{ IOException -> 0x0055 }
            epson.common.httpclient.IAHttpClient$HttpResponse r4 = r3.parseResponse(r4, r1)     // Catch:{ IOException -> 0x0055 }
            r3.disconnect()     // Catch:{ all -> 0x005b }
            monitor-exit(r3)
            return r4
        L_0x004b:
            r4 = move-exception
            goto L_0x004f
        L_0x004d:
            r4 = move-exception
            throw r4     // Catch:{ all -> 0x004b }
        L_0x004f:
            r0.close()     // Catch:{ IOException -> 0x0052 }
        L_0x0052:
            throw r4     // Catch:{ IOException -> 0x0055 }
        L_0x0053:
            r4 = move-exception
            goto L_0x0057
        L_0x0055:
            r4 = move-exception
            throw r4     // Catch:{ all -> 0x0053 }
        L_0x0057:
            r3.disconnect()     // Catch:{ all -> 0x005b }
            throw r4     // Catch:{ all -> 0x005b }
        L_0x005b:
            r4 = move-exception
            monitor-exit(r3)
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.common.httpclient.IAHttpClient.execute(epson.common.httpclient.IAHttpClient$HttpPost):epson.common.httpclient.IAHttpClient$HttpResponse");
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(13:0|1|2|3|4|(3:5|6|(2:8|9)(1:39))|15|16|17|18|19|20|22) */
    /* JADX WARNING: Can't wrap try/catch for region: R(7:23|27|28|29|30|31|32) */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:18:0x0073 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:29:0x0081 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:31:0x0084 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public epson.common.httpclient.IAHttpClient.HttpResponse executeFile(epson.common.httpclient.IAHttpClient.HttpGet r7) throws java.io.IOException {
        /*
            r6 = this;
            epson.common.httpclient.IAHttpClient$HttpResponse r0 = new epson.common.httpclient.IAHttpClient$HttpResponse
            r0.<init>()
            java.net.HttpURLConnection r0 = r6.connect(r7)     // Catch:{ IOException -> 0x0087 }
            r6.conn = r0     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r0 = r6.conn     // Catch:{ IOException -> 0x0087 }
            java.lang.String r1 = "GET"
            r0.setRequestMethod(r1)     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r0 = r6.conn     // Catch:{ IOException -> 0x0087 }
            r1 = 1
            r0.setDoInput(r1)     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r0 = r6.conn     // Catch:{ IOException -> 0x0087 }
            r6.makeHeader(r0, r7)     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r0 = r6.conn     // Catch:{ IOException -> 0x0087 }
            r0.connect()     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r0 = r6.conn     // Catch:{ IOException -> 0x0087 }
            r1 = 0
            epson.common.httpclient.IAHttpClient$HttpResponse r0 = r6.parseResponse(r0, r1)     // Catch:{ IOException -> 0x0087 }
            java.io.DataInputStream r2 = new java.io.DataInputStream     // Catch:{ IOException -> 0x0087 }
            java.net.HttpURLConnection r3 = r6.conn     // Catch:{ IOException -> 0x0087 }
            java.io.InputStream r3 = r3.getInputStream()     // Catch:{ IOException -> 0x0087 }
            r2.<init>(r3)     // Catch:{ IOException -> 0x0087 }
            java.io.BufferedOutputStream r3 = new java.io.BufferedOutputStream     // Catch:{ IOException -> 0x0087 }
            java.io.FileOutputStream r4 = new java.io.FileOutputStream     // Catch:{ IOException -> 0x0087 }
            java.lang.String r7 = r7.getEntityFileName()     // Catch:{ IOException -> 0x0087 }
            r4.<init>(r7)     // Catch:{ IOException -> 0x0087 }
            r7 = 1024(0x400, float:1.435E-42)
            r3.<init>(r4, r7)     // Catch:{ IOException -> 0x0087 }
            byte[] r7 = new byte[r7]     // Catch:{ IOException -> 0x007c }
        L_0x0046:
            int r4 = r2.read(r7)     // Catch:{ IOException -> 0x007c }
            r5 = -1
            if (r4 == r5) goto L_0x006d
            r3.write(r7, r1, r4)     // Catch:{ IOException -> 0x0051 }
            goto L_0x0046
        L_0x0051:
            r7 = move-exception
            java.lang.String r0 = "IAHttpClient"
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x007c }
            r1.<init>()     // Catch:{ IOException -> 0x007c }
            java.lang.String r4 = "error: in executeFile() : "
            r1.append(r4)     // Catch:{ IOException -> 0x007c }
            java.lang.String r4 = r7.toString()     // Catch:{ IOException -> 0x007c }
            r1.append(r4)     // Catch:{ IOException -> 0x007c }
            java.lang.String r1 = r1.toString()     // Catch:{ IOException -> 0x007c }
            epson.print.Util.EPLog.m318w((java.lang.String) r0, (java.lang.String) r1)     // Catch:{ IOException -> 0x007c }
            throw r7     // Catch:{ IOException -> 0x007c }
        L_0x006d:
            r3.flush()     // Catch:{ IOException -> 0x007c }
            r2.close()     // Catch:{ IOException -> 0x0073 }
        L_0x0073:
            r3.close()     // Catch:{ IOException -> 0x0076 }
        L_0x0076:
            r6.disconnect()
            return r0
        L_0x007a:
            r7 = move-exception
            goto L_0x007e
        L_0x007c:
            r7 = move-exception
            throw r7     // Catch:{ all -> 0x007a }
        L_0x007e:
            r2.close()     // Catch:{ IOException -> 0x0081 }
        L_0x0081:
            r3.close()     // Catch:{ IOException -> 0x0084 }
        L_0x0084:
            throw r7     // Catch:{ IOException -> 0x0087 }
        L_0x0085:
            r7 = move-exception
            goto L_0x0089
        L_0x0087:
            r7 = move-exception
            throw r7     // Catch:{ all -> 0x0085 }
        L_0x0089:
            r6.disconnect()
            throw r7
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.common.httpclient.IAHttpClient.executeFile(epson.common.httpclient.IAHttpClient$HttpGet):epson.common.httpclient.IAHttpClient$HttpResponse");
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(17:0|1|2|(1:4)|5|6|7|(3:8|9|(4:11|12|13|(1:15)(2:48|16))(1:47))|22|23|24|25|26|27|28|29|30) */
    /* JADX WARNING: Can't wrap try/catch for region: R(7:31|35|36|37|38|39|40) */
    /* JADX WARNING: Missing exception handler attribute for start block: B:25:0x00a0 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:27:0x00a3 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:37:0x00b4 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:39:0x00b7 */
    /* JADX WARNING: Unknown top exception splitter block from list: {B:27:0x00a3=Splitter:B:27:0x00a3, B:39:0x00b7=Splitter:B:39:0x00b7} */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public epson.common.httpclient.IAHttpClient.HttpResponse executeFile(epson.common.httpclient.IAHttpClient.HttpPost r10) throws java.io.IOException {
        /*
            r9 = this;
            epson.common.httpclient.IAHttpClient$HttpResponse r0 = new epson.common.httpclient.IAHttpClient$HttpResponse
            r0.<init>()
            java.net.HttpURLConnection r0 = r9.connect(r10)     // Catch:{ IOException -> 0x00ba }
            r9.conn = r0     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r0 = r9.conn     // Catch:{ IOException -> 0x00ba }
            java.lang.String r1 = "POST"
            r0.setRequestMethod(r1)     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r0 = r9.conn     // Catch:{ IOException -> 0x00ba }
            r1 = 1
            r0.setDoInput(r1)     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r0 = r9.conn     // Catch:{ IOException -> 0x00ba }
            r0.setDoOutput(r1)     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r0 = r9.conn     // Catch:{ IOException -> 0x00ba }
            r9.makeHeader(r0, r10)     // Catch:{ IOException -> 0x00ba }
            java.lang.Integer r0 = r10.getContentLength()     // Catch:{ IOException -> 0x00ba }
            if (r0 == 0) goto L_0x0035
            java.net.HttpURLConnection r0 = r9.conn     // Catch:{ IOException -> 0x00ba }
            java.lang.Integer r2 = r10.getContentLength()     // Catch:{ IOException -> 0x00ba }
            int r2 = r2.intValue()     // Catch:{ IOException -> 0x00ba }
            r0.setFixedLengthStreamingMode(r2)     // Catch:{ IOException -> 0x00ba }
        L_0x0035:
            java.io.DataOutputStream r0 = new java.io.DataOutputStream     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r2 = r9.conn     // Catch:{ IOException -> 0x00ba }
            java.io.OutputStream r2 = r2.getOutputStream()     // Catch:{ IOException -> 0x00ba }
            r0.<init>(r2)     // Catch:{ IOException -> 0x00ba }
            java.io.BufferedInputStream r2 = new java.io.BufferedInputStream     // Catch:{ IOException -> 0x00ba }
            java.io.FileInputStream r3 = new java.io.FileInputStream     // Catch:{ IOException -> 0x00ba }
            java.lang.String r4 = r10.getEntityFileName()     // Catch:{ IOException -> 0x00ba }
            r3.<init>(r4)     // Catch:{ IOException -> 0x00ba }
            r4 = 1024(0x400, float:1.435E-42)
            r2.<init>(r3, r4)     // Catch:{ IOException -> 0x00ba }
            int r3 = r10.getEntityFileDataOffset()     // Catch:{ IOException -> 0x00ba }
            long r5 = (long) r3     // Catch:{ IOException -> 0x00ba }
            r2.skip(r5)     // Catch:{ IOException -> 0x00ba }
            java.net.HttpURLConnection r3 = r9.conn     // Catch:{ IOException -> 0x00ba }
            r3.connect()     // Catch:{ IOException -> 0x00ba }
            byte[] r3 = new byte[r4]     // Catch:{ IOException -> 0x00af }
            r4 = 0
            r5 = 0
        L_0x0061:
            int r6 = r2.read(r3)     // Catch:{ IOException -> 0x00af }
            r7 = -1
            if (r6 == r7) goto L_0x009a
            int r7 = r5 + r6
            int r8 = r10.getEntityFileDataSize()     // Catch:{ IOException -> 0x007e }
            if (r7 >= r8) goto L_0x0075
            r0.write(r3, r4, r6)     // Catch:{ IOException -> 0x007e }
            r5 = r7
            goto L_0x0061
        L_0x0075:
            int r10 = r10.getEntityFileDataSize()     // Catch:{ IOException -> 0x007e }
            int r10 = r10 - r5
            r0.write(r3, r4, r10)     // Catch:{ IOException -> 0x007e }
            goto L_0x009a
        L_0x007e:
            r10 = move-exception
            java.lang.String r1 = "IAHttpClient"
            java.lang.StringBuilder r3 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x00af }
            r3.<init>()     // Catch:{ IOException -> 0x00af }
            java.lang.String r4 = "error: in executeFile() : "
            r3.append(r4)     // Catch:{ IOException -> 0x00af }
            java.lang.String r4 = r10.toString()     // Catch:{ IOException -> 0x00af }
            r3.append(r4)     // Catch:{ IOException -> 0x00af }
            java.lang.String r3 = r3.toString()     // Catch:{ IOException -> 0x00af }
            epson.print.Util.EPLog.m318w((java.lang.String) r1, (java.lang.String) r3)     // Catch:{ IOException -> 0x00af }
            throw r10     // Catch:{ IOException -> 0x00af }
        L_0x009a:
            r0.flush()     // Catch:{ IOException -> 0x00af }
            r0.close()     // Catch:{ IOException -> 0x00a0 }
        L_0x00a0:
            r2.close()     // Catch:{ IOException -> 0x00a3 }
        L_0x00a3:
            java.net.HttpURLConnection r10 = r9.conn     // Catch:{ IOException -> 0x00ba }
            epson.common.httpclient.IAHttpClient$HttpResponse r10 = r9.parseResponse(r10, r1)     // Catch:{ IOException -> 0x00ba }
            r9.disconnect()
            return r10
        L_0x00ad:
            r10 = move-exception
            goto L_0x00b1
        L_0x00af:
            r10 = move-exception
            throw r10     // Catch:{ all -> 0x00ad }
        L_0x00b1:
            r0.close()     // Catch:{ IOException -> 0x00b4 }
        L_0x00b4:
            r2.close()     // Catch:{ IOException -> 0x00b7 }
        L_0x00b7:
            throw r10     // Catch:{ IOException -> 0x00ba }
        L_0x00b8:
            r10 = move-exception
            goto L_0x00bc
        L_0x00ba:
            r10 = move-exception
            throw r10     // Catch:{ all -> 0x00b8 }
        L_0x00bc:
            r9.disconnect()
            throw r10
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.common.httpclient.IAHttpClient.executeFile(epson.common.httpclient.IAHttpClient$HttpPost):epson.common.httpclient.IAHttpClient$HttpResponse");
    }

    private void makeHeader(HttpURLConnection httpURLConnection, HttpBase httpBase) {
        if (httpBase.getContentType() != null) {
            httpURLConnection.setRequestProperty("Content-Type", httpBase.getContentType());
        }
        if (httpBase.getContentEncoding() != null) {
            httpURLConnection.setRequestProperty("Content-Encoding", httpBase.getContentEncoding());
        }
        if (httpBase.getChunked() != null && httpBase.getChunked().equals(true)) {
            httpURLConnection.setRequestProperty("Transfer-Encoding", "chunked");
        }
    }

    private HttpResponse parseResponse(HttpURLConnection httpURLConnection, boolean z) throws IOException {
        InputStream inputStream;
        HttpResponse httpResponse = new HttpResponse();
        httpResponse.setResponseCode(httpURLConnection.getResponseCode());
        httpResponse.setContentLength(Integer.valueOf(httpURLConnection.getContentLength()));
        if (httpURLConnection.getContentEncoding() != null) {
            httpResponse.setContentEncoding(httpURLConnection.getContentEncoding());
        }
        if (httpURLConnection.getContentType() != null) {
            httpResponse.setContentType(httpURLConnection.getContentType());
        }
        EPLog.m313i(TAG, "ResponseCode = " + httpResponse.getResponseCode() + " Content-Type = " + httpResponse.getContentType() + " Content-Length = " + httpResponse.getContentLength());
        if (z) {
            switch (httpResponse.getResponseCode() / 100) {
                case 1:
                case 2:
                case 3:
                    inputStream = httpURLConnection.getInputStream();
                    break;
                default:
                    inputStream = httpURLConnection.getErrorStream();
                    break;
            }
            if (inputStream != null) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                try {
                    byte[] bArr = new byte[1024];
                    while (true) {
                        int read = inputStream.read(bArr);
                        if (read <= 0) {
                            httpResponse.setEntity(byteArrayOutputStream.toByteArray());
                            try {
                                byteArrayOutputStream.close();
                            } catch (IOException unused) {
                            }
                        } else {
                            byteArrayOutputStream.write(bArr, 0, read);
                        }
                    }
                } catch (FileNotFoundException e) {
                    EPLog.m307e(TAG, e.getMessage());
                } catch (Throwable th) {
                    try {
                        byteArrayOutputStream.close();
                    } catch (IOException unused2) {
                    }
                    throw th;
                }
            }
        }
        return httpResponse;
    }

    public static class HttpGet extends HttpBase {
        public /* bridge */ /* synthetic */ Boolean getChunked() {
            return super.getChunked();
        }

        public /* bridge */ /* synthetic */ String getContentEncoding() {
            return super.getContentEncoding();
        }

        public /* bridge */ /* synthetic */ Integer getContentLength() {
            return super.getContentLength();
        }

        public /* bridge */ /* synthetic */ String getContentType() {
            return super.getContentType();
        }

        public /* bridge */ /* synthetic */ ByteArrayOutputStream getEntity() throws IOException {
            return super.getEntity();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataOffset() {
            return super.getEntityFileDataOffset();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataSize() {
            return super.getEntityFileDataSize();
        }

        public /* bridge */ /* synthetic */ String getEntityFileName() {
            return super.getEntityFileName();
        }

        public /* bridge */ /* synthetic */ URL getURI() {
            return super.getURI();
        }

        public /* bridge */ /* synthetic */ void setChunked(Boolean bool) {
            super.setChunked(bool);
        }

        public /* bridge */ /* synthetic */ void setContentEncoding(String str) {
            super.setContentEncoding(str);
        }

        public /* bridge */ /* synthetic */ void setContentLength(Integer num) {
            super.setContentLength(num);
        }

        public /* bridge */ /* synthetic */ void setContentType(String str) {
            super.setContentType(str);
        }

        public /* bridge */ /* synthetic */ void setEntity(byte[] bArr) {
            super.setEntity(bArr);
        }

        public /* bridge */ /* synthetic */ void setEntityFile(String str, int i, int i2) {
            super.setEntityFile(str, i, i2);
        }

        public HttpGet(String str) {
            super(str);
        }
    }

    public static class HttpPost extends HttpBase {
        public /* bridge */ /* synthetic */ Boolean getChunked() {
            return super.getChunked();
        }

        public /* bridge */ /* synthetic */ String getContentEncoding() {
            return super.getContentEncoding();
        }

        public /* bridge */ /* synthetic */ Integer getContentLength() {
            return super.getContentLength();
        }

        public /* bridge */ /* synthetic */ String getContentType() {
            return super.getContentType();
        }

        public /* bridge */ /* synthetic */ ByteArrayOutputStream getEntity() throws IOException {
            return super.getEntity();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataOffset() {
            return super.getEntityFileDataOffset();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataSize() {
            return super.getEntityFileDataSize();
        }

        public /* bridge */ /* synthetic */ String getEntityFileName() {
            return super.getEntityFileName();
        }

        public /* bridge */ /* synthetic */ URL getURI() {
            return super.getURI();
        }

        public /* bridge */ /* synthetic */ void setChunked(Boolean bool) {
            super.setChunked(bool);
        }

        public /* bridge */ /* synthetic */ void setContentEncoding(String str) {
            super.setContentEncoding(str);
        }

        public /* bridge */ /* synthetic */ void setContentLength(Integer num) {
            super.setContentLength(num);
        }

        public /* bridge */ /* synthetic */ void setContentType(String str) {
            super.setContentType(str);
        }

        public /* bridge */ /* synthetic */ void setEntity(byte[] bArr) {
            super.setEntity(bArr);
        }

        public /* bridge */ /* synthetic */ void setEntityFile(String str, int i, int i2) {
            super.setEntityFile(str, i, i2);
        }

        public HttpPost(String str) {
            super(str);
        }

        public static byte[] getUrlEncodedFormEntity(List<BasicNameValuePair> list, String str) throws UnsupportedEncodingException {
            StringBuilder sb = new StringBuilder();
            boolean z = true;
            for (BasicNameValuePair next : list) {
                if (z) {
                    z = false;
                } else {
                    sb.append("&");
                }
                sb.append(URLEncoder.encode(next.getName(), str));
                sb.append(CommonDefine.EQUAL_MARK);
                sb.append(URLEncoder.encode(next.getValue(), str));
            }
            return sb.toString().getBytes(str);
        }
    }

    public static class HttpResponse extends HttpBase {
        private int responseCode = 0;

        public /* bridge */ /* synthetic */ Boolean getChunked() {
            return super.getChunked();
        }

        public /* bridge */ /* synthetic */ String getContentEncoding() {
            return super.getContentEncoding();
        }

        public /* bridge */ /* synthetic */ Integer getContentLength() {
            return super.getContentLength();
        }

        public /* bridge */ /* synthetic */ String getContentType() {
            return super.getContentType();
        }

        public /* bridge */ /* synthetic */ ByteArrayOutputStream getEntity() throws IOException {
            return super.getEntity();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataOffset() {
            return super.getEntityFileDataOffset();
        }

        public /* bridge */ /* synthetic */ int getEntityFileDataSize() {
            return super.getEntityFileDataSize();
        }

        public /* bridge */ /* synthetic */ String getEntityFileName() {
            return super.getEntityFileName();
        }

        public /* bridge */ /* synthetic */ URL getURI() {
            return super.getURI();
        }

        public /* bridge */ /* synthetic */ void setChunked(Boolean bool) {
            super.setChunked(bool);
        }

        public /* bridge */ /* synthetic */ void setContentEncoding(String str) {
            super.setContentEncoding(str);
        }

        public /* bridge */ /* synthetic */ void setContentLength(Integer num) {
            super.setContentLength(num);
        }

        public /* bridge */ /* synthetic */ void setContentType(String str) {
            super.setContentType(str);
        }

        public /* bridge */ /* synthetic */ void setEntity(byte[] bArr) {
            super.setEntity(bArr);
        }

        public /* bridge */ /* synthetic */ void setEntityFile(String str, int i, int i2) {
            super.setEntityFile(str, i, i2);
        }

        public int getResponseCode() {
            return responseCode;
        }

        public void setResponseCode(int i) {
            responseCode = i;
        }
    }

    static abstract class HttpBase {
        private Boolean chunked = null;
        private String contentEncoding;
        private Integer contentLength = null;
        private String contentType;
        private byte[] entityBuffer;
        private int entityFileDataOffset;
        private int entityFileDataSize;
        private String entityFileName;
        private URL url = null;

        public HttpBase() {
        }

        public HttpBase(String str) {
            try {
                url = new URL(str);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        public URL getURI() {
            return url;
        }

        public String getContentType() {
            return contentType;
        }

        public void setContentType(String str) {
            contentType = str;
        }

        public String getContentEncoding() {
            return contentEncoding;
        }

        public void setContentEncoding(String str) {
            contentEncoding = str;
        }

        public Boolean getChunked() {
            return chunked;
        }

        public void setChunked(Boolean bool) {
            chunked = bool;
        }

        public Integer getContentLength() {
            return contentLength;
        }

        public void setContentLength(Integer num) {
            contentLength = num;
        }

        public void setEntity(byte[] bArr) {
            entityBuffer = bArr;
        }

        public ByteArrayOutputStream getEntity() throws IOException {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(this.entityBuffer.length);
            byteArrayOutputStream.write(this.entityBuffer);
            return byteArrayOutputStream;
        }

        public String getEntityFileName() {
            return entityFileName;
        }

        public int getEntityFileDataOffset() {
            return entityFileDataOffset;
        }

        public int getEntityFileDataSize() {
            return entityFileDataSize;
        }

        public void setEntityFile(String str, int i, int i2) {
            entityFileName = str;
            entityFileDataOffset = i;
            entityFileDataSize = i2;
        }
    }
}
