package com.ifpdos.factorytest.util;

import android.util.Log;
import java.io.Closeable;
import java.io.InputStream;
import java.io.OutputStream;

/* JADX INFO: loaded from: classes.dex */
public class CommonUtils {
    private static final int COPY_BUFFER_SIZE = 1024;
    private static final String TAG = "CommonUtils";

    public static void safeClose(Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        } catch (Exception unused) {
            Log.e(TAG, "An exception has occurred in CommonUtils.safeClose");
        }
    }

    public static void safeSleep(long j) {
        try {
            Thread.sleep(j);
        } catch (Exception unused) {
            Log.e(TAG, "An exception has occurred in CommonUtils.safeSleep");
        }
    }

    public static boolean copyStream(InputStream inputStream, OutputStream outputStream) {
        try {
            byte[] bArr = new byte[1024];
            while (true) {
                int i = inputStream.read(bArr);
                if (i == -1) {
                    return true;
                }
                outputStream.write(bArr, 0, i);
            }
        } catch (Exception unused) {
            Log.e(TAG, "An exception has occurred in CommonUtils.copyStream");
            return false;
        }
    }

    public static String bytesToString(byte[] bArr) {
        StringBuilder sb = new StringBuilder();
        if (bArr != null) {
            for (byte b : bArr) {
                sb.append(String.format("0x%02x ", Byte.valueOf(b)));
            }
        }
        return sb.toString();
    }
}
