package epson.server.utils;

import android.content.Context;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import com.evernote.edam.limits.Constants;
import epson.common.ExternalFileUtils;
import epson.print.CommonDefine;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public final class MyUtility {
    public static File createTempFile(Context context, String str, String str2) {
        if (str2.indexOf(CommonDefine.SLASH) != -1 || str2.indexOf("\\") != -1) {
            return null;
        }
        File file = new File(ExternalFileUtils.getInstance(context).getScannedImageDir(), str2);
        try {
            FileInputStream fileInputStream = new FileInputStream(new File(str));
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            byte[] bArr = new byte[1024];
            while (true) {
                int read = fileInputStream.read(bArr);
                if (read > 0) {
                    fileOutputStream.write(bArr, 0, read);
                } else {
                    fileInputStream.close();
                    fileOutputStream.close();
                    return file;
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(5:10|11|12|13|32) */
    /* JADX WARNING: Code restructure failed: missing block: B:33:?, code lost:
        return;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:12:0x0018 */
    /* JADX WARNING: Removed duplicated region for block: B:24:0x002a A[SYNTHETIC, Splitter:B:24:0x002a] */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0031 A[SYNTHETIC, Splitter:B:28:0x0031] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static void copy(java.io.File r3, java.io.File r4) throws java.io.IOException {
        /*
            r0 = 0
            java.io.FileInputStream r1 = new java.io.FileInputStream     // Catch:{ all -> 0x0026 }
            r1.<init>(r3)     // Catch:{ all -> 0x0026 }
            java.io.FileOutputStream r3 = new java.io.FileOutputStream     // Catch:{ all -> 0x0024 }
            r3.<init>(r4)     // Catch:{ all -> 0x0024 }
            r4 = 8192(0x2000, float:1.14794E-41)
            byte[] r4 = new byte[r4]     // Catch:{ all -> 0x0021 }
        L_0x000f:
            int r0 = r1.read(r4)     // Catch:{ all -> 0x0021 }
            if (r0 > 0) goto L_0x001c
            r1.close()     // Catch:{ IOException -> 0x0018 }
        L_0x0018:
            r3.close()     // Catch:{ IOException -> 0x001b }
        L_0x001b:
            return
        L_0x001c:
            r2 = 0
            r3.write(r4, r2, r0)     // Catch:{ all -> 0x0021 }
            goto L_0x000f
        L_0x0021:
            r4 = move-exception
            r0 = r3
            goto L_0x0028
        L_0x0024:
            r4 = move-exception
            goto L_0x0028
        L_0x0026:
            r4 = move-exception
            r1 = r0
        L_0x0028:
            if (r1 == 0) goto L_0x002f
            r1.close()     // Catch:{ IOException -> 0x002e }
            goto L_0x002f
        L_0x002e:
        L_0x002f:
            if (r0 == 0) goto L_0x0034
            r0.close()     // Catch:{ IOException -> 0x0034 }
        L_0x0034:
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: epson.server.utils.MyUtility.copy(java.io.File, java.io.File):void");
    }

    public static void createFolder(String str) {
        File file = new File(str);
        if (!file.exists()) {
            file.mkdirs();
        }
    }

    public static double mathRound(double d, int i) {
        if (i <= 0) {
            return 0.0d;
        }
        int i2 = 1;
        for (int i3 = 0; i3 < i; i3++) {
            i2 *= 10;
        }
        double d2 = (double) i2;
        return ((double) Math.round(d * d2)) / d2;
    }

    public String doNet(Context context) {
        String str = "";
        WiFiDirectManager.setPriorityToSimpleAP(context, false);
        try {
            URLConnection openConnection = new URL("https://support.epson.net/healthcheck/iPrint.html").openConnection();
            openConnection.setConnectTimeout(Constants.EDAM_BUSINESS_NOTEBOOKS_MAX);
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(openConnection.getInputStream()));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    return str;
                }
                str = str + readLine;
            }
        } catch (MalformedURLException unused) {
            return str;
        } catch (IOException unused2) {
            return str;
        }
    }
}
