导航菜单

页面标题

页面副标题

RummyCircle v11000.89 - RNFSManager.java 源代码

正在查看: RummyCircle v11000.89 应用的 RNFSManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.rnfs;

import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.util.Base64;
import android.util.SparseArray;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.neovisionaries.ws.client.F;
import com.truecaller.android.sdk.TruecallerSdkScope;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.URL;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@com.facebook.react.module.annotations.a(name = RNFSManager.MODULE_NAME)
public class RNFSManager extends ReactContextBaseJavaModule {
    static final String MODULE_NAME = "RNFSManager";
    private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath";
    private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory";
    private static final String RNFSDocumentDirectoryPath = "RNFSDocumentDirectoryPath";
    private static final String RNFSDownloadDirectoryPath = "RNFSDownloadDirectoryPath";
    private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath";
    private static final String RNFSExternalDirectoryPath = "RNFSExternalDirectoryPath";
    private static final String RNFSExternalStorageDirectoryPath = "RNFSExternalStorageDirectoryPath";
    private static final String RNFSFileTypeDirectory = "RNFSFileTypeDirectory";
    private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
    private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath";
    private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath";
    private SparseArray<com.rnfs.d> downloaders;
    private ReactApplicationContext reactContext;
    private SparseArray<com.rnfs.h> uploaders;

    public class a extends j {
        public final File b;
        public final Promise c;
        public final String d;

        public a(File file, Promise promise, String str) {
            super();
            this.b = file;
            this.c = promise;
            this.d = str;
        }

        @Override
        public final void onPostExecute(Exception exc) {
            Exception exc2 = exc;
            Promise promise = this.c;
            if (exc2 == null) {
                this.b.delete();
                promise.resolve(Boolean.TRUE);
            } else {
                exc2.printStackTrace();
                RNFSManager.this.reject(promise, this.d, exc2);
            }
        }
    }

    public class b extends j {
        public final Promise b;
        public final String c;

        public b(Promise promise, String str) {
            super();
            this.b = promise;
            this.c = str;
        }

        @Override
        public final void onPostExecute(Exception exc) {
            Exception exc2 = exc;
            Promise promise = this.b;
            if (exc2 == null) {
                promise.resolve((Object) null);
            } else {
                exc2.printStackTrace();
                RNFSManager.this.reject(promise, this.c, exc2);
            }
        }
    }

    public class c {
        public final int a;
        public final Promise b;
        public final ReadableMap c;

        public c(int i, Promise promise, ReadableMap readableMap) {
            this.a = i;
            this.b = promise;
            this.c = readableMap;
        }

        public final void a(com.rnfs.b bVar) {
            Exception exc = bVar.c;
            Promise promise = this.b;
            if (exc != null) {
                RNFSManager.this.reject(promise, this.c.getString("toFile"), bVar.c);
            } else {
                WritableMap createMap = Arguments.createMap();
                createMap.putInt("jobId", this.a);
                createMap.putInt("statusCode", bVar.a);
                createMap.putDouble("bytesWritten", bVar.b);
                promise.resolve(createMap);
            }
        }
    }

    public class d {
        public final int a;

        public d(int i) {
            this.a = i;
        }

        public final void a(int i, long j, HashMap hashMap) {
            WritableMap createMap = Arguments.createMap();
            for (Map.Entry entry : hashMap.entrySet()) {
                createMap.putString((String) entry.getKey(), (String) entry.getValue());
            }
            WritableMap createMap2 = Arguments.createMap();
            createMap2.putInt("jobId", this.a);
            createMap2.putInt("statusCode", i);
            createMap2.putDouble("contentLength", j);
            createMap2.putMap("headers", createMap);
            RNFSManager rNFSManager = RNFSManager.this;
            rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "DownloadBegin", createMap2);
        }
    }

    public class e {
        public final int a;

        public e(int i) {
            this.a = i;
        }
    }

    public class f {
        public final int a;
        public final Promise b;
        public final ReadableMap c;

        public f(int i, Promise promise, ReadableMap readableMap) {
            this.a = i;
            this.b = promise;
            this.c = readableMap;
        }

        public final void a(F f) {
            Exception exc = (Exception) f.e;
            Promise promise = this.b;
            if (exc != null) {
                RNFSManager.this.reject(promise, this.c.getString("toUrl"), (Exception) f.e);
            } else {
                WritableMap createMap = Arguments.createMap();
                createMap.putInt("jobId", this.a);
                createMap.putInt("statusCode", f.b);
                createMap.putMap("headers", (WritableMap) f.d);
                createMap.putString("body", f.c);
                promise.resolve(createMap);
            }
        }
    }

    public class g {
        public final int a;

        public g(int i) {
            this.a = i;
        }
    }

    public class h {
        public final int a;

        public h(int i) {
            this.a = i;
        }
    }

    public class j extends AsyncTask<String, Void, Exception> {
        public j() {
        }

        @Override
        public final Exception doInBackground(String[] strArr) {
            String[] strArr2 = strArr;
            RNFSManager rNFSManager = RNFSManager.this;
            try {
                String str = strArr2[0];
                String str2 = strArr2[1];
                InputStream inputStream = rNFSManager.getInputStream(str);
                OutputStream outputStream = rNFSManager.getOutputStream(str2, false);
                byte[] bArr = new byte[TruecallerSdkScope.BUTTON_SHAPE_ROUNDED];
                while (true) {
                    int read = inputStream.read(bArr);
                    if (read <= 0) {
                        inputStream.close();
                        outputStream.close();
                        return null;
                    }
                    outputStream.write(bArr, 0, read);
                    Thread.yield();
                }
            } catch (Exception e) {
                return e;
            }
        }
    }

    public RNFSManager(ReactApplicationContext reactApplicationContext) {
        super(reactApplicationContext);
        this.downloaders = new SparseArray<>();
        this.uploaders = new SparseArray<>();
        this.reactContext = reactApplicationContext;
    }

    private void DeleteRecursive(File file) {
        if (file.isDirectory()) {
            for (File file2 : file.listFiles()) {
                DeleteRecursive(file2);
            }
        }
        file.delete();
    }

    private void copyInputStream(java.io.InputStream r8, java.lang.String r9, java.lang.String r10, com.facebook.react.bridge.Promise r11) {
        throw new UnsupportedOperationException("Method not decompiled: com.rnfs.RNFSManager.copyInputStream(java.io.InputStream, java.lang.String, java.lang.String, com.facebook.react.bridge.Promise):void");
    }

    private Uri getFileUri(String str, boolean z) throws com.rnfs.e {
        Uri parse = Uri.parse(str);
        if (parse.getScheme() != null) {
            return parse;
        }
        File file = new File(str);
        if (!z && file.isDirectory()) {
            throw new com.rnfs.e("EISDIR", androidx.camera.core.impl.utils.i.c("EISDIR: illegal operation on a directory, read '", str, "'"));
        }
        return Uri.parse("file://" + str);
    }

    public InputStream getInputStream(String str) throws com.rnfs.e {
        try {
            InputStream openInputStream = this.reactContext.getContentResolver().openInputStream(getFileUri(str, false));
            if (openInputStream != null) {
                return openInputStream;
            }
            throw new com.rnfs.e("ENOENT", androidx.camera.core.impl.utils.i.c("ENOENT: could not open an input stream for '", str, "'"));
        } catch (FileNotFoundException e2) {
            throw new com.rnfs.e("ENOENT", "ENOENT: " + e2.getMessage() + ", open '" + str + "'");
        }
    }

    private static byte[] getInputStreamBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[TruecallerSdkScope.BUTTON_SHAPE_ROUNDED];
        while (true) {
            try {
                int read = inputStream.read(bArr);
                if (read == -1) {
                    break;
                }
                byteArrayOutputStream.write(bArr, 0, read);
            } catch (Throwable th) {
                try {
                    byteArrayOutputStream.close();
                } catch (IOException unused) {
                }
                throw th;
            }
        }
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        try {
            byteArrayOutputStream.close();
        } catch (IOException unused2) {
        }
        return byteArray;
    }

    private String getOriginalFilepath(String str, boolean z) throws com.rnfs.e {
        Uri fileUri = getFileUri(str, z);
        if (fileUri.getScheme().equals("content")) {
            try {
                Cursor query = this.reactContext.getContentResolver().query(fileUri, null, null, null, null);
                if (query.moveToFirst()) {
                    str = query.getString(query.getColumnIndexOrThrow("_data"));
                }
                query.close();
            } catch (IllegalArgumentException unused) {
            }
        }
        return str;
    }

    public OutputStream getOutputStream(String str, boolean z) throws com.rnfs.e {
        try {
            OutputStream openOutputStream = this.reactContext.getContentResolver().openOutputStream(getFileUri(str, false), z ? "wa" : getWriteAccessByAPILevel());
            if (openOutputStream != null) {
                return openOutputStream;
            }
            throw new com.rnfs.e("ENOENT", androidx.camera.core.impl.utils.i.c("ENOENT: could not open an output stream for '", str, "'"));
        } catch (FileNotFoundException e2) {
            throw new com.rnfs.e("ENOENT", "ENOENT: " + e2.getMessage() + ", open '" + str + "'");
        }
    }

    private int getResIdentifier(String str) {
        boolean z = true;
        String substring = str.substring(str.lastIndexOf(".") + 1);
        String substring2 = str.substring(0, str.lastIndexOf("."));
        if (!substring.equals("png") && !substring.equals("jpg") && !substring.equals("jpeg") && !substring.equals("bmp") && !substring.equals("gif") && !substring.equals("webp") && !substring.equals("psd") && !substring.equals("svg") && !substring.equals("tiff")) {
            z = false;
        }
        return getReactApplicationContext().getResources().getIdentifier(substring2, Boolean.valueOf(z).booleanValue() ? "drawable" : "raw", getReactApplicationContext().getPackageName());
    }

    private String getWriteAccessByAPILevel() {
        return Build.VERSION.SDK_INT <= 28 ? "w" : "rwt";
    }

    public void reject(Promise promise, String str, Exception exc) {
        if (exc instanceof FileNotFoundException) {
            rejectFileNotFound(promise, str);
        } else if (!(exc instanceof com.rnfs.e)) {
            promise.reject((String) null, exc.getMessage());
        } else {
            com.rnfs.e eVar = (com.rnfs.e) exc;
            promise.reject(eVar.a, eVar.getMessage());
        }
    }

    private void rejectFileIsDirectory(Promise promise) {
        promise.reject("EISDIR", "EISDIR: illegal operation on a directory, read");
    }

    private void rejectFileNotFound(Promise promise, String str) {
        promise.reject("ENOENT", "ENOENT: no such file or directory, open '" + str + "'");
    }

    public void sendEvent(ReactContext reactContext, String str, WritableMap writableMap) {
        reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(str, writableMap);
    }

    @ReactMethod
    public void appendFile(String str, String str2, Promise promise) {
        try {
            byte[] decode = Base64.decode(str2, 0);
            OutputStream outputStream = getOutputStream(str, true);
            outputStream.write(decode);
            outputStream.close();
            promise.resolve((Object) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void copyFile(String str, String str2, ReadableMap readableMap, Promise promise) {
        new b(promise, str).execute(str, str2);
    }

    @ReactMethod
    public void copyFileAssets(String str, String str2, Promise promise) {
        try {
            copyInputStream(getReactApplicationContext().getAssets().open(str), str, str2, promise);
        } catch (IOException unused) {
            reject(promise, str, new Exception(String.format("Asset '%s' could not be opened", str)));
        }
    }

    @ReactMethod
    public void copyFileRes(String str, String str2, Promise promise) {
        try {
            copyInputStream(getReactApplicationContext().getResources().openRawResource(getResIdentifier(str)), str, str2, promise);
        } catch (Exception unused) {
            reject(promise, str, new Exception(String.format("Res '%s' could not be opened", str)));
        }
    }

    @ReactMethod
    public void downloadFile(ReadableMap readableMap, Promise promise) {
        try {
            File file = new File(readableMap.getString("toFile"));
            URL url = new URL(readableMap.getString("fromUrl"));
            int i2 = readableMap.getInt("jobId");
            ReadableMap map = readableMap.getMap("headers");
            int i3 = readableMap.getInt("progressInterval");
            int i4 = readableMap.getInt("progressDivider");
            int i5 = readableMap.getInt("readTimeout");
            int i6 = readableMap.getInt("connectionTimeout");
            boolean z = readableMap.getBoolean("hasBeginCallback");
            boolean z2 = readableMap.getBoolean("hasProgressCallback");
            com.rnfs.a aVar = new com.rnfs.a();
            aVar.a = url;
            aVar.b = file;
            aVar.c = map;
            aVar.d = i3;
            aVar.e = i4;
            aVar.f = i5;
            aVar.g = i6;
            aVar.h = new c(i2, promise, readableMap);
            if (z) {
                aVar.i = new d(i2);
            }
            if (z2) {
                aVar.j = new e(i2);
            }
            com.rnfs.d dVar = new com.rnfs.d();
            dVar.execute(aVar);
            this.downloaders.put(i2, dVar);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, readableMap.getString("toFile"), e2);
        }
    }

    @ReactMethod
    public void exists(String str, Promise promise) {
        try {
            promise.resolve(Boolean.valueOf(new File(str).exists()));
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void existsAssets(String str, Promise promise) {
        try {
            AssetManager assets = getReactApplicationContext().getAssets();
            try {
                String[] list = assets.list(str);
                if (list != null && list.length > 0) {
                    promise.resolve(Boolean.TRUE);
                    return;
                }
            } catch (Exception unused) {
            }
            InputStream inputStream = null;
            try {
                try {
                    inputStream = assets.open(str);
                    promise.resolve(Boolean.TRUE);
                    if (inputStream == null) {
                        return;
                    }
                } catch (Exception unused2) {
                    promise.resolve(Boolean.FALSE);
                    if (inputStream == null) {
                        return;
                    }
                }
                try {
                    inputStream.close();
                } catch (Exception unused3) {
                }
            } catch (Throwable th) {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception unused4) {
                    }
                }
                throw th;
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void existsRes(String str, Promise promise) {
        try {
            if (getResIdentifier(str) > 0) {
                promise.resolve(Boolean.TRUE);
            } else {
                promise.resolve(Boolean.FALSE);
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void getAllExternalFilesDirs(Promise promise) {
        File[] externalFilesDirs = getReactApplicationContext().getExternalFilesDirs(null);
        WritableArray createArray = Arguments.createArray();
        for (File file : externalFilesDirs) {
            if (file != null) {
                createArray.pushString(file.getAbsolutePath());
            }
        }
        promise.resolve(createArray);
    }

    public Map<String, Object> getConstants() {
        HashMap hashMap = new HashMap();
        hashMap.put(RNFSDocumentDirectory, 0);
        hashMap.put(RNFSDocumentDirectoryPath, getReactApplicationContext().getFilesDir().getAbsolutePath());
        hashMap.put(RNFSTemporaryDirectoryPath, getReactApplicationContext().getCacheDir().getAbsolutePath());
        hashMap.put(RNFSPicturesDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
        hashMap.put(RNFSCachesDirectoryPath, getReactApplicationContext().getCacheDir().getAbsolutePath());
        hashMap.put(RNFSDownloadDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
        hashMap.put(RNFSFileTypeRegular, 0);
        hashMap.put(RNFSFileTypeDirectory, 1);
        File externalStorageDirectory = Environment.getExternalStorageDirectory();
        if (externalStorageDirectory != null) {
            hashMap.put(RNFSExternalStorageDirectoryPath, externalStorageDirectory.getAbsolutePath());
        } else {
            hashMap.put(RNFSExternalStorageDirectoryPath, null);
        }
        File externalFilesDir = getReactApplicationContext().getExternalFilesDir(null);
        if (externalFilesDir != null) {
            hashMap.put(RNFSExternalDirectoryPath, externalFilesDir.getAbsolutePath());
        } else {
            hashMap.put(RNFSExternalDirectoryPath, null);
        }
        File externalCacheDir = getReactApplicationContext().getExternalCacheDir();
        if (externalCacheDir != null) {
            hashMap.put(RNFSExternalCachesDirectoryPath, externalCacheDir.getAbsolutePath());
        } else {
            hashMap.put(RNFSExternalCachesDirectoryPath, null);
        }
        return hashMap;
    }

    @ReactMethod
    public void getFSInfo(Promise promise) {
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        StatFs statFs2 = new StatFs(Environment.getExternalStorageDirectory().getPath());
        long totalBytes = statFs.getTotalBytes();
        long freeBytes = statFs.getFreeBytes();
        long totalBytes2 = statFs2.getTotalBytes();
        long freeBytes2 = statFs2.getFreeBytes();
        WritableMap createMap = Arguments.createMap();
        createMap.putDouble("totalSpace", totalBytes);
        createMap.putDouble("freeSpace", freeBytes);
        createMap.putDouble("totalSpaceEx", totalBytes2);
        createMap.putDouble("freeSpaceEx", freeBytes2);
        promise.resolve(createMap);
    }

    public String getName() {
        return MODULE_NAME;
    }

    @ReactMethod
    public void hash(String str, String str2, Promise promise) {
        try {
            HashMap hashMap = new HashMap();
            hashMap.put("md5", "MD5");
            hashMap.put("sha1", "SHA-1");
            hashMap.put("sha224", "SHA-224");
            hashMap.put("sha256", "SHA-256");
            hashMap.put("sha384", "SHA-384");
            hashMap.put("sha512", "SHA-512");
            if (!hashMap.containsKey(str2)) {
                throw new Exception("Invalid hash algorithm");
            }
            File file = new File(str);
            if (file.isDirectory()) {
                rejectFileIsDirectory(promise);
                return;
            }
            if (!file.exists()) {
                rejectFileNotFound(promise, str);
                return;
            }
            MessageDigest messageDigest = MessageDigest.getInstance((String) hashMap.get(str2));
            FileInputStream fileInputStream = new FileInputStream(str);
            byte[] bArr = new byte[10240];
            while (true) {
                int read = fileInputStream.read(bArr);
                if (read == -1) {
                    break;
                } else {
                    messageDigest.update(bArr, 0, read);
                }
            }
            StringBuilder sb = new StringBuilder();
            for (byte b2 : messageDigest.digest()) {
                sb.append(String.format("%02x", Integer.valueOf(b2 & 255)));
            }
            promise.resolve(sb.toString());
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void mkdir(String str, ReadableMap readableMap, Promise promise) {
        try {
            File file = new File(str);
            file.mkdirs();
            if (!file.exists()) {
                throw new Exception("Directory could not be created");
            }
            promise.resolve((Object) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void moveFile(String str, String str2, ReadableMap readableMap, Promise promise) {
        try {
            File file = new File(str);
            if (file.renameTo(new File(str2))) {
                promise.resolve(Boolean.TRUE);
            } else {
                new a(file, promise, str).execute(str, str2);
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void read(String str, int i2, int i3, Promise promise) {
        try {
            InputStream inputStream = getInputStream(str);
            byte[] bArr = new byte[i2];
            inputStream.skip(i3);
            promise.resolve(Base64.encodeToString(bArr, 0, inputStream.read(bArr, 0, i2), 2));
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void readDir(String str, Promise promise) {
        try {
            File file = new File(str);
            if (!file.exists()) {
                throw new Exception("Folder does not exist");
            }
            File[] listFiles = file.listFiles();
            WritableArray createArray = Arguments.createArray();
            for (File file2 : listFiles) {
                WritableMap createMap = Arguments.createMap();
                createMap.putDouble("mtime", file2.lastModified() / 1000.0d);
                createMap.putString("name", file2.getName());
                createMap.putString("path", file2.getAbsolutePath());
                createMap.putDouble("size", file2.length());
                createMap.putInt("type", file2.isDirectory() ? 1 : 0);
                createArray.pushMap(createMap);
            }
            promise.resolve(createArray);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void readDirAssets(String str, Promise promise) {
        int i2;
        try {
            AssetManager assets = getReactApplicationContext().getAssets();
            String[] list = assets.list(str);
            WritableArray createArray = Arguments.createArray();
            for (String str2 : list) {
                WritableMap createMap = Arguments.createMap();
                createMap.putString("name", str2);
                if (!str.isEmpty()) {
                    str2 = String.format("%s/%s", str, str2);
                }
                createMap.putString("path", str2);
                int i3 = 1;
                try {
                    AssetFileDescriptor openFd = assets.openFd(str2);
                    if (openFd != null) {
                        i2 = (int) openFd.getLength();
                        try {
                            openFd.close();
                            i3 = 0;
                        } catch (IOException e2) {
                            e = e2;
                            i3 = 1 ^ (e.getMessage().contains("compressed") ? 1 : 0);
                            createMap.putInt("size", i2);
                            createMap.putInt("type", i3);
                            createArray.pushMap(createMap);
                        }
                    } else {
                        i2 = 0;
                    }
                } catch (IOException e3) {
                    e = e3;
                    i2 = 0;
                }
                createMap.putInt("size", i2);
                createMap.putInt("type", i3);
                createArray.pushMap(createMap);
            }
            promise.resolve(createArray);
        } catch (IOException e4) {
            reject(promise, str, e4);
        }
    }

    @ReactMethod
    public void readFile(String str, Promise promise) {
        try {
            promise.resolve(Base64.encodeToString(getInputStreamBytes(getInputStream(str)), 2));
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void readFileAssets(String str, Promise promise) {
        InputStream inputStream = null;
        try {
            try {
                inputStream = getReactApplicationContext().getAssets().open(str, 0);
            } catch (Throwable th) {
                if (0 != 0) {
                    try {
                        inputStream.close();
                    } catch (IOException unused) {
                    }
                }
                throw th;
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
            if (0 == 0) {
                return;
            }
        }
        if (inputStream == null) {
            reject(promise, str, new Exception("Failed to open file"));
            if (inputStream != null) {
                try {
                    inputStream.close();
                    return;
                } catch (IOException unused2) {
                    return;
                }
            }
            return;
        }
        byte[] bArr = new byte[inputStream.available()];
        inputStream.read(bArr);
        promise.resolve(Base64.encodeToString(bArr, 2));
        try {
            inputStream.close();
        } catch (IOException unused3) {
        }
    }

    @ReactMethod
    public void readFileRes(String str, Promise promise) {
        InputStream inputStream = null;
        try {
            try {
                inputStream = getReactApplicationContext().getResources().openRawResource(getResIdentifier(str));
            } catch (Throwable th) {
                if (0 != 0) {
                    try {
                        inputStream.close();
                    } catch (IOException unused) {
                    }
                }
                throw th;
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
            if (0 == 0) {
                return;
            }
        }
        if (inputStream == null) {
            reject(promise, str, new Exception("Failed to open file"));
            if (inputStream != null) {
                try {
                    inputStream.close();
                    return;
                } catch (IOException unused2) {
                    return;
                }
            }
            return;
        }
        byte[] bArr = new byte[inputStream.available()];
        inputStream.read(bArr);
        promise.resolve(Base64.encodeToString(bArr, 2));
        try {
            inputStream.close();
        } catch (IOException unused3) {
        }
    }

    @ReactMethod
    public void scanFile(String str, Promise promise) {
        MediaScannerConnection.scanFile(getReactApplicationContext(), new String[]{str}, null, new i(promise));
    }

    @ReactMethod
    public void setReadable(String str, Boolean bool, Boolean bool2, Promise promise) {
        try {
            File file = new File(str);
            if (!file.exists()) {
                throw new Exception("File does not exist");
            }
            file.setReadable(bool.booleanValue(), bool2.booleanValue());
            promise.resolve(Boolean.TRUE);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void stat(String str, Promise promise) {
        try {
            String originalFilepath = getOriginalFilepath(str, true);
            File file = new File(originalFilepath);
            if (!file.exists()) {
                throw new Exception("File does not exist");
            }
            WritableMap createMap = Arguments.createMap();
            createMap.putInt("ctime", (int) (file.lastModified() / 1000));
            createMap.putInt("mtime", (int) (file.lastModified() / 1000));
            createMap.putDouble("size", file.length());
            createMap.putInt("type", file.isDirectory() ? 1 : 0);
            createMap.putString("originalFilepath", originalFilepath);
            promise.resolve(createMap);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void stopDownload(int i2) {
        com.rnfs.d dVar = this.downloaders.get(i2);
        if (dVar != null) {
            dVar.b.set(true);
        }
    }

    @ReactMethod
    public void stopUpload(int i2) {
        com.rnfs.h hVar = this.uploaders.get(i2);
        if (hVar != null) {
            hVar.c.set(true);
        }
    }

    @ReactMethod
    public void touch(String str, double d2, double d3, Promise promise) {
        try {
            promise.resolve(Boolean.valueOf(new File(str).setLastModified((long) d2)));
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void unlink(String str, Promise promise) {
        try {
            File file = new File(str);
            if (!file.exists()) {
                throw new Exception("File does not exist");
            }
            DeleteRecursive(file);
            promise.resolve((Object) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void uploadFiles(ReadableMap readableMap, Promise promise) {
        String str;
        try {
            ReadableArray array = readableMap.getArray("files");
            URL url = new URL(readableMap.getString("toUrl"));
            int i2 = readableMap.getInt("jobId");
            ReadableMap map = readableMap.getMap("headers");
            ReadableMap map2 = readableMap.getMap("fields");
            String string = readableMap.getString("method");
            boolean z = readableMap.getBoolean("binaryStreamOnly");
            boolean z2 = readableMap.getBoolean("hasBeginCallback");
            boolean z3 = readableMap.getBoolean("hasProgressCallback");
            ArrayList<ReadableMap> arrayList = new ArrayList<>();
            com.rnfs.f fVar = new com.rnfs.f();
            str = "toUrl";
            for (int i3 = 0; i3 < array.size(); i3++) {
                try {
                    arrayList.add(array.getMap(i3));
                } catch (Exception e2) {
                    e = e2;
                    e.printStackTrace();
                    reject(promise, readableMap.getString(str), e);
                    return;
                }
            }
            fVar.a = url;
            fVar.b = arrayList;
            fVar.d = map;
            fVar.f = string;
            fVar.e = map2;
            fVar.c = z;
            fVar.g = new f(i2, promise, readableMap);
            if (z2) {
                fVar.i = new g(i2);
            }
            if (z3) {
                fVar.h = new h(i2);
            }
            com.rnfs.h hVar = new com.rnfs.h();
            hVar.execute(fVar);
            this.uploaders.put(i2, hVar);
        } catch (Exception e3) {
            e = e3;
            str = "toUrl";
        }
    }

    @ReactMethod
    public void write(String str, String str2, int i2, Promise promise) {
        try {
            byte[] decode = Base64.decode(str2, 0);
            if (i2 < 0) {
                OutputStream outputStream = getOutputStream(str, true);
                outputStream.write(decode);
                outputStream.close();
            } else {
                RandomAccessFile randomAccessFile = new RandomAccessFile(str, "rw");
                randomAccessFile.seek(i2);
                randomAccessFile.write(decode);
                randomAccessFile.close();
            }
            promise.resolve((Object) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    @ReactMethod
    public void writeFile(String str, String str2, ReadableMap readableMap, Promise promise) {
        try {
            byte[] decode = Base64.decode(str2, 0);
            OutputStream outputStream = getOutputStream(str, false);
            outputStream.write(decode);
            outputStream.close();
            promise.resolve((Object) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            reject(promise, str, e2);
        }
    }

    public class i implements MediaScannerConnection.MediaScannerConnectionClient {
        public final Promise a;

        public i(Promise promise) {
            this.a = promise;
        }

        @Override
        public final void onScanCompleted(String str, Uri uri) {
            this.a.resolve(str);
        }

        @Override
        public final void onMediaScannerConnected() {
        }
    }

    @ReactMethod
    public void addListener(String str) {
    }

    @ReactMethod
    public void removeListeners(Integer num) {
    }

    @ReactMethod
    public void pathForBundle(String str, Promise promise) {
    }

    @ReactMethod
    public void pathForGroup(String str, Promise promise) {
    }
}