package epson.server.utils;

import android.content.Context;

import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import com.evernote.edam.limits.Constants;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import epson.common.ExternalFileUtils;
import epson.print.CommonDefine;

public final class MyUtility {
    public static File createTempFile(Context context, String str, String str2) throws IOException {
        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;
                }
            }
        }
    }


    public static void copy(java.io.File r3, java.io.File r4) throws java.io.IOException {

        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 = i2;
        return (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;
        }
    }
}
