导航菜单

页面标题

页面副标题

Zepto v25.1.4 - ReactNativeBlobUtil.java 源代码

正在查看: Zepto v25.1.4 应用的 ReactNativeBlobUtil.java JAVA 源代码文件

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


package com.ReactNativeBlobUtil;

import android.app.DownloadManager;
import android.content.Intent;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.support.v4.media.a;
import android.util.Base64;
import android.util.SparseArray;
import androidx.annotation.NonNull;
import com.ReactNativeBlobUtil.ReactNativeBlobUtilMediaCollection;
import com.ReactNativeBlobUtil.Utils.FileDescription;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
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.DeviceEventManagerModule;
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.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;

public class ReactNativeBlobUtil extends ReactContextBaseJavaModule {
    private final ReactNativeBlobUtilImpl delegate;

    public ReactNativeBlobUtil(ReactApplicationContext reactApplicationContext) {
        super(reactApplicationContext);
        this.delegate = new ReactNativeBlobUtilImpl(reactApplicationContext);
    }

    @com.facebook.react.bridge.ReactMethod
    public void actionViewIntent(java.lang.String r9, java.lang.String r10, @javax.annotation.Nullable java.lang.String r11, com.facebook.react.bridge.Promise r12) {
        throw new UnsupportedOperationException("Method not decompiled: com.ReactNativeBlobUtil.ReactNativeBlobUtil.actionViewIntent(java.lang.String, java.lang.String, java.lang.String, com.facebook.react.bridge.Promise):void");
    }

    @ReactMethod
    public void addCompleteDownload(ReadableMap readableMap, Promise promise) {
        this.delegate.getClass();
        DownloadManager downloadManager = (DownloadManager) ReactNativeBlobUtilImpl.f6866b.getSystemService("download");
        if (readableMap == null || !readableMap.hasKey("path")) {
            promise.reject("EINVAL", "ReactNativeBlobUtil.addCompleteDownload config or path missing.");
            return;
        }
        String b2 = ReactNativeBlobUtilUtils.b(readableMap.getString("path"));
        if (b2 == null) {
            promise.reject("EINVAL", "ReactNativeBlobUtil.addCompleteDownload can not resolve URI:" + readableMap.getString("path"));
        } else {
            try {
                downloadManager.addCompletedDownload(readableMap.hasKey("title") ? readableMap.getString("title") : "", readableMap.hasKey("description") ? readableMap.getString("description") : "", true, readableMap.hasKey("mime") ? readableMap.getString("mime") : null, b2, Long.valueOf(ReactNativeBlobUtilFS.g(b2).getString("size")).longValue(), readableMap.hasKey("showNotification") && readableMap.getBoolean("showNotification"));
                promise.resolve((Object) null);
            } catch (Exception e) {
                promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
            }
        }
    }

    @ReactMethod
    public void addListener(String str) {
    }

    @ReactMethod
    public void cancelRequest(String str, Callback callback) {
        this.delegate.getClass();
        try {
            ReactNativeBlobUtilReq.a(str);
            callback.invoke(new Object[]{null, str});
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage(), null});
        }
    }

    @ReactMethod
    public void closeStream(String str, Callback callback) {
        this.delegate.getClass();
        try {
            HashMap hashMap = ReactNativeBlobUtilStream.d;
            FileOutputStream fileOutputStream = ((ReactNativeBlobUtilStream) hashMap.get(str)).f6927c;
            hashMap.remove(str);
            fileOutputStream.close();
            callback.invoke(new Object[0]);
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage()});
        }
    }

    @com.facebook.react.bridge.ReactMethod
    @androidx.annotation.RequiresApi
    public void copyToInternal(java.lang.String r7, java.lang.String r8, com.facebook.react.bridge.Promise r9) {
        throw new UnsupportedOperationException("Method not decompiled: com.ReactNativeBlobUtil.ReactNativeBlobUtil.copyToInternal(java.lang.String, java.lang.String, com.facebook.react.bridge.Promise):void");
    }

    @ReactMethod
    public void copyToMediaStore(ReadableMap readableMap, String str, String str2, Promise promise) {
        this.delegate.getClass();
        if (!readableMap.hasKey("name") || !readableMap.hasKey("parentFolder") || !readableMap.hasKey("mimeType")) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "invalid filedata: " + readableMap.toString());
            return;
        }
        if (str == null) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "invalid mediatype");
            return;
        }
        if (str2 == null) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "invalid path");
            return;
        }
        FileDescription fileDescription = new FileDescription(readableMap.getString("name"), readableMap.getString("mimeType"), readableMap.getString("parentFolder"));
        ReactNativeBlobUtilMediaCollection.MediaType valueOf = ReactNativeBlobUtilMediaCollection.MediaType.valueOf(str);
        ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
        Uri a2 = ReactNativeBlobUtilMediaCollection.a(fileDescription, valueOf);
        if (a2 == null) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "File could not be created");
        } else if (ReactNativeBlobUtilMediaCollection.b(a2, str2, false, promise, ReactNativeBlobUtilImpl.f6866b)) {
            promise.resolve(a2.toString());
        }
    }

    @ReactMethod
    public void cp(String str, String str2, Callback callback) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6883a;

            public final String f6884b;

            public final Callback f6885c;

            public AnonymousClass5(String str3, String str22, Callback callback2) {
                r1 = str3;
                r2 = str22;
                r3 = callback2;
            }

            @Override
            public final void run() {
                throw new UnsupportedOperationException("Method not decompiled: com.ReactNativeBlobUtil.ReactNativeBlobUtilImpl.AnonymousClass5.run():void");
            }
        });
    }

    @ReactMethod
    public void createFile(String str, String str2, String str3, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6876a;

            public final String f6877b;

            public final String f6878c;
            public final Promise d;

            public AnonymousClass2(String str4, String str22, String str32, Promise promise2) {
                r1 = str4;
                r2 = str22;
                r3 = str32;
                r4 = promise2;
            }

            @Override
            public final void run() {
                String str4 = r1;
                String str5 = r3;
                Promise promise2 = r4;
                try {
                    String b2 = ReactNativeBlobUtilUtils.b(str4);
                    File file = new File(b2);
                    boolean createNewFile = file.createNewFile();
                    boolean equals = str5.equals("uri");
                    String str6 = r2;
                    if (equals) {
                        File file2 = new File(str6.replace("ReactNativeBlobUtil-file://", ""));
                        if (!file2.exists()) {
                            promise2.reject("ENOENT", "Source file : " + str6 + " does not exist");
                            return;
                        }
                        FileInputStream fileInputStream = new FileInputStream(file2);
                        FileOutputStream fileOutputStream = new FileOutputStream(file);
                        byte[] bArr = new byte[10240];
                        for (int read = fileInputStream.read(bArr); read > 0; read = fileInputStream.read(bArr)) {
                            fileOutputStream.write(bArr, 0, read);
                        }
                        fileInputStream.close();
                        fileOutputStream.close();
                    } else {
                        if (!createNewFile) {
                            promise2.reject("EEXIST", "File `" + b2 + "` already exists");
                            return;
                        }
                        new FileOutputStream(file).write(ReactNativeBlobUtilUtils.c(str6, str5));
                    }
                    promise2.resolve(b2);
                } catch (Exception e) {
                    promise2.reject("EUNSPECIFIED", e.getLocalizedMessage());
                }
            }
        });
    }

    @ReactMethod
    public void createFileASCII(String str, ReadableArray readableArray, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6879a;

            public final ReadableArray f6880b;

            public final Promise f6881c;

            public AnonymousClass3(String str2, ReadableArray readableArray2, Promise promise2) {
                r1 = str2;
                r2 = readableArray2;
                r3 = promise2;
            }

            @Override
            public final void run() {
                String str2 = r1;
                ReadableArray readableArray2 = r2;
                Promise promise2 = r3;
                try {
                    String b2 = ReactNativeBlobUtilUtils.b(str2);
                    File file = new File(b2);
                    if (!file.createNewFile()) {
                        promise2.reject("EEXIST", "File at path `" + b2 + "` already exists");
                        return;
                    }
                    FileOutputStream fileOutputStream = new FileOutputStream(file);
                    byte[] bArr = new byte[readableArray2.size()];
                    for (int i = 0; i < readableArray2.size(); i++) {
                        bArr[i] = (byte) readableArray2.getInt(i);
                    }
                    fileOutputStream.write(bArr);
                    promise2.resolve(b2);
                } catch (Exception e) {
                    promise2.reject("EUNSPECIFIED", e.getLocalizedMessage());
                }
            }
        });
    }

    @ReactMethod
    public void createMediaFile(ReadableMap readableMap, String str, Promise promise) {
        this.delegate.getClass();
        if (!readableMap.hasKey("name") || !readableMap.hasKey("parentFolder") || !readableMap.hasKey("mimeType")) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "invalid filedata: " + readableMap.toString());
            return;
        }
        if (str == null) {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "invalid mediatype");
        }
        FileDescription fileDescription = new FileDescription(readableMap.getString("name"), readableMap.getString("mimeType"), readableMap.getString("parentFolder"));
        ReactNativeBlobUtilMediaCollection.MediaType valueOf = ReactNativeBlobUtilMediaCollection.MediaType.valueOf(str);
        ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
        Uri a2 = ReactNativeBlobUtilMediaCollection.a(fileDescription, valueOf);
        if (a2 != null) {
            promise.resolve(a2.toString());
        } else {
            promise.reject("ReactNativeBlobUtil.createMediaFile", "File could not be created");
        }
    }

    @ReactMethod
    public void df(Callback callback) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.d.execute(new Runnable() {

            public final Callback f6875a;

            public AnonymousClass12(Callback callback2) {
                r1 = callback2;
            }

            @Override
            public final void run() {
                ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
                StatFs statFs = new StatFs(reactApplicationContext.getFilesDir().getPath());
                WritableMap createMap = Arguments.createMap();
                createMap.putString("internal_free", String.valueOf(statFs.getFreeBytes()));
                createMap.putString("internal_total", String.valueOf(statFs.getTotalBytes()));
                File externalFilesDir = reactApplicationContext.getExternalFilesDir(null);
                if (externalFilesDir != null) {
                    StatFs statFs2 = new StatFs(externalFilesDir.getPath());
                    createMap.putString("external_free", String.valueOf(statFs2.getFreeBytes()));
                    createMap.putString("external_total", String.valueOf(statFs2.getTotalBytes()));
                } else {
                    createMap.putString("external_free", "-1");
                    createMap.putString("external_total", "-1");
                }
                r1.invoke(new Object[]{null, createMap});
            }
        });
    }

    @ReactMethod
    public void enableProgressReport(String str, int i, int i2) {
        this.delegate.getClass();
        ReactNativeBlobUtilReq.y.put(str, new ReactNativeBlobUtilProgressConfig(i, i2));
    }

    @ReactMethod
    public void enableUploadProgressReport(String str, int i, int i2) {
        this.delegate.getClass();
        ReactNativeBlobUtilReq.z.put(str, new ReactNativeBlobUtilProgressConfig(i, i2));
    }

    @ReactMethod
    public void exists(String str, Callback callback) {
        this.delegate.getClass();
        if (str != null && str.startsWith("bundle-assets://")) {
            try {
                ReactNativeBlobUtilImpl.f6866b.getAssets().openFd(str.replace("bundle-assets://", ""));
                callback.invoke(new Object[]{Boolean.TRUE, Boolean.FALSE});
                return;
            } catch (IOException unused) {
                Boolean bool = Boolean.FALSE;
                callback.invoke(new Object[]{bool, bool});
                return;
            }
        }
        String b2 = ReactNativeBlobUtilUtils.b(str);
        if (b2 != null) {
            callback.invoke(new Object[]{Boolean.valueOf(new File(b2).exists()), Boolean.valueOf(new File(b2).isDirectory())});
        } else {
            Boolean bool2 = Boolean.FALSE;
            callback.invoke(new Object[]{bool2, bool2});
        }
    }

    @ReactMethod
    public void fetchBlob(ReadableMap readableMap, String str, String str2, String str3, ReadableMap readableMap2, String str4, Callback callback) {
        ReactNativeBlobUtilImpl reactNativeBlobUtilImpl = this.delegate;
        reactNativeBlobUtilImpl.getClass();
        new ReactNativeBlobUtilReq(readableMap, str, str2, str3, readableMap2, str4, null, reactNativeBlobUtilImpl.f6868a, callback).run();
    }

    @ReactMethod
    public void fetchBlobForm(ReadableMap readableMap, String str, String str2, String str3, ReadableMap readableMap2, ReadableArray readableArray, Callback callback) {
        ReactNativeBlobUtilImpl reactNativeBlobUtilImpl = this.delegate;
        reactNativeBlobUtilImpl.getClass();
        new ReactNativeBlobUtilReq(readableMap, str, str2, str3, readableMap2, null, readableArray, reactNativeBlobUtilImpl.f6868a, callback).run();
    }

    @com.facebook.react.bridge.ReactMethod
    @androidx.annotation.RequiresApi
    public void getBlob(java.lang.String r6, java.lang.String r7, com.facebook.react.bridge.Promise r8) {
        throw new UnsupportedOperationException("Method not decompiled: com.ReactNativeBlobUtil.ReactNativeBlobUtil.getBlob(java.lang.String, java.lang.String, com.facebook.react.bridge.Promise):void");
    }

    public Map<String, Object> getConstants() {
        HashMap hashMap = new HashMap();
        ReactApplicationContext reactApplicationContext = getReactApplicationContext();
        HashMap hashMap2 = new HashMap();
        File filesDir = reactApplicationContext.getFilesDir();
        hashMap2.put("DocumentDir", filesDir != null ? filesDir.getAbsolutePath() : "");
        File cacheDir = reactApplicationContext.getCacheDir();
        hashMap2.put("CacheDir", cacheDir != null ? cacheDir.getAbsolutePath() : "");
        hashMap2.put("DCIMDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_DCIM));
        hashMap2.put("PictureDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_PICTURES));
        hashMap2.put("MusicDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_MUSIC));
        hashMap2.put("DownloadDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_DOWNLOADS));
        hashMap2.put("MovieDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_MOVIES));
        hashMap2.put("RingtoneDir", ReactNativeBlobUtilFS.b(reactApplicationContext, Environment.DIRECTORY_RINGTONES));
        if (Environment.getExternalStorageState().equals("mounted")) {
            hashMap2.put("SDCardDir", ReactNativeBlobUtilFS.b(reactApplicationContext, null));
            File externalFilesDir = reactApplicationContext.getExternalFilesDir(null);
            if (externalFilesDir == null || externalFilesDir.getParentFile() == null) {
                hashMap2.put("SDCardApplicationDir", "");
            } else {
                hashMap2.put("SDCardApplicationDir", externalFilesDir.getParentFile().getAbsolutePath());
            }
        } else {
            hashMap2.put("SDCardDir", "");
            hashMap2.put("SDCardApplicationDir", "");
        }
        hashMap2.put("MainBundleDir", reactApplicationContext.getApplicationInfo().dataDir);
        hashMap2.put("LibraryDir", "");
        hashMap2.put("ApplicationSupportDir", "");
        hashMap.putAll(hashMap2);
        getReactApplicationContext();
        hashMap.putAll(ReactNativeBlobUtilFS.c());
        return hashMap;
    }

    @ReactMethod
    public void getContentIntent(String str, Promise promise) {
        this.delegate.getClass();
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        if (str != null) {
            intent.setType(str);
        } else {
            intent.setType("*/*");
        }
        SparseArray sparseArray = ReactNativeBlobUtilImpl.f;
        Integer num = ReactNativeBlobUtilConst.f6861a;
        sparseArray.put(num.intValue(), promise);
        ReactNativeBlobUtilImpl.f6866b.startActivityForResult(intent, num.intValue(), (Bundle) null);
    }

    @NonNull
    public String getName() {
        return "ReactNativeBlobUtil";
    }

    @ReactMethod
    public void getSDCardApplicationDir(Promise promise) {
        this.delegate.getClass();
        ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
        if (!Environment.getExternalStorageState().equals("mounted")) {
            promise.reject("ReactNativeBlobUtil.getSDCardApplicationDir", "External storage not mounted");
            return;
        }
        try {
            promise.resolve(reactApplicationContext.getExternalFilesDir(null).getParentFile().getAbsolutePath());
        } catch (Exception e) {
            promise.reject("ReactNativeBlobUtil.getSDCardApplicationDir", e.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void getSDCardDir(Promise promise) {
        this.delegate.getClass();
        ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
        if (!Environment.getExternalStorageState().equals("mounted")) {
            promise.reject("ReactNativeBlobUtil.getSDCardDir", "External storage not mounted");
            return;
        }
        try {
            promise.resolve(reactApplicationContext.getExternalFilesDir(null).getAbsolutePath());
        } catch (Exception e) {
            promise.reject("ReactNativeBlobUtil.getSDCardDir", e.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void hash(String str, String str2, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6869a;

            public final String f6870b;

            public final Promise f6871c;

            public AnonymousClass10(String str3, String str22, Promise promise2) {
                r1 = str3;
                r2 = str22;
                r3 = promise2;
            }

            @Override
            public final void run() {
                String str3 = r1;
                String str4 = r2;
                Promise promise2 = r3;
                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(str4)) {
                        promise2.reject("EINVAL", "Invalid algorithm '" + str4 + "', must be one of md5, sha1, sha224, sha256, sha384, sha512");
                        return;
                    }
                    String b2 = ReactNativeBlobUtilUtils.b(str3);
                    File file = new File(b2);
                    if (file.isDirectory()) {
                        promise2.reject("EISDIR", "Expecting a file but '" + b2 + "' is a directory");
                        return;
                    }
                    if (!file.exists()) {
                        promise2.reject("ENOENT", "No such file '" + b2 + "'");
                        return;
                    }
                    MessageDigest messageDigest = MessageDigest.getInstance((String) hashMap.get(str4));
                    FileInputStream fileInputStream = new FileInputStream(b2);
                    byte[] bArr = new byte[1048576];
                    if (file.length() != 0) {
                        while (true) {
                            int read = fileInputStream.read(bArr);
                            if (read == -1) {
                                break;
                            } else {
                                messageDigest.update(bArr, 0, read);
                            }
                        }
                    }
                    StringBuilder sb = new StringBuilder();
                    for (byte b3 : messageDigest.digest()) {
                        sb.append(String.format("%02x", Byte.valueOf(b3)));
                    }
                    promise2.resolve(sb.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                    promise2.reject("EUNSPECIFIED", e.getLocalizedMessage());
                }
            }
        });
    }

    @ReactMethod
    public void ls(String str, Promise promise) {
        this.delegate.getClass();
        try {
            String b2 = ReactNativeBlobUtilUtils.b(str);
            File file = new File(b2);
            if (!file.exists()) {
                promise.reject("ENOENT", "No such file '" + b2 + "'");
                return;
            }
            if (!file.isDirectory()) {
                promise.reject("ENOTDIR", "Not a directory '" + b2 + "'");
                return;
            }
            String[] list = new File(b2).list();
            WritableArray createArray = Arguments.createArray();
            for (String str2 : list) {
                createArray.pushString(str2);
            }
            promise.resolve(createArray);
        } catch (Exception e) {
            e.printStackTrace();
            promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void lstat(String str, Callback callback) {
        this.delegate.getClass();
        new AsyncTask<String, Integer, Integer>() {

            public final Callback f6863a;

            public AnonymousClass1(Callback callback2) {
                r1 = callback2;
            }

            @Override
            public final Integer doInBackground(String[] strArr) {
                String[] strArr2 = strArr;
                WritableArray createArray = Arguments.createArray();
                String str2 = strArr2[0];
                Callback callback2 = r1;
                if (str2 == null) {
                    callback2.invoke(new Object[]{"the path specified for lstat is either `null` or `undefined`."});
                } else {
                    File file = new File(strArr2[0]);
                    if (file.exists()) {
                        if (file.isDirectory()) {
                            for (String str3 : file.list()) {
                                createArray.pushMap(ReactNativeBlobUtilFS.g(file.getPath() + "/" + str3));
                            }
                        } else {
                            createArray.pushMap(ReactNativeBlobUtilFS.g(file.getAbsolutePath()));
                        }
                        callback2.invoke(new Object[]{null, createArray});
                    } else {
                        callback2.invoke(new Object[]{a.s(new StringBuilder("failed to lstat path `"), strArr2[0], "` because it does not exist or it is not a folder")});
                    }
                }
                return 0;
            }
        }.execute(ReactNativeBlobUtilUtils.b(str));
    }

    @ReactMethod
    public void mkdir(String str, Promise promise) {
        this.delegate.getClass();
        String b2 = ReactNativeBlobUtilUtils.b(str);
        File file = new File(b2);
        if (file.exists()) {
            StringBuilder sb = new StringBuilder();
            sb.append(file.isDirectory() ? "Folder" : "File");
            sb.append(" '");
            sb.append(b2);
            sb.append("' already exists");
            promise.reject("EEXIST", sb.toString());
            return;
        }
        try {
            if (file.mkdirs()) {
                promise.resolve(Boolean.TRUE);
                return;
            }
            promise.reject("EUNSPECIFIED", "mkdir failed to create some or all directories in '" + b2 + "'");
        } catch (Exception e) {
            promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void mv(String str, String str2, Callback callback) {
        this.delegate.getClass();
        String b2 = ReactNativeBlobUtilUtils.b(str);
        String b3 = ReactNativeBlobUtilUtils.b(str2);
        File file = new File(b2);
        if (!file.exists()) {
            callback.invoke(new Object[]{a.D("Source file at path `", b2, "` does not exist")});
            return;
        }
        try {
            File file2 = new File(b3);
            File parentFile = file2.getParentFile();
            if (parentFile != null && !parentFile.exists()) {
                callback.invoke(new Object[]{"mv failed because the destination directory doesn't exist"});
                return;
            }
            if (file2.exists()) {
                file2.delete();
            }
            if (file.renameTo(file2)) {
                callback.invoke(new Object[0]);
            } else {
                callback.invoke(new Object[]{"mv failed for unknown reasons"});
            }
        } catch (Exception e) {
            callback.invoke(new Object[]{e.toString()});
        }
    }

    @ReactMethod
    public void readFile(String str, String str2, boolean z, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6886a;

            public final String f6887b;

            public final boolean f6888c;
            public final Promise d;

            public AnonymousClass6(String str3, String str22, boolean z2, Promise promise2) {
                r1 = str3;
                r2 = str22;
                r3 = z2;
                r4 = promise2;
            }

            @Override
            public final void run() {
                throw new UnsupportedOperationException("Method not decompiled: com.ReactNativeBlobUtil.ReactNativeBlobUtilImpl.AnonymousClass6.run():void");
            }
        });
    }

    @ReactMethod
    public void readStream(String str, String str2, int i, int i2, String str3) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.d.execute(new Runnable() {

            public final ReactApplicationContext f6872a;

            public final String f6873b;

            public final String f6874c;
            public final int d;
            public final int e;
            public final String f;

            public AnonymousClass11(ReactApplicationContext reactApplicationContext, String str4, String str22, int i3, int i22, String str32) {
                r1 = reactApplicationContext;
                r2 = str4;
                r3 = str22;
                r4 = i3;
                r5 = i22;
                r6 = str32;
            }

            @Override
            public final void run() {
                ReactNativeBlobUtilStream reactNativeBlobUtilStream = new ReactNativeBlobUtilStream(r1);
                String str4 = r3;
                String str5 = r6;
                ReactApplicationContext reactApplicationContext = ReactNativeBlobUtilImpl.f6866b;
                String str6 = r2;
                String b2 = ReactNativeBlobUtilUtils.b(str6);
                if (b2 != null) {
                    str6 = b2;
                }
                try {
                    int i3 = str4.equalsIgnoreCase("base64") ? 4095 : 4096;
                    int i4 = r4;
                    if (i4 > 0) {
                        i3 = i4;
                    }
                    InputStream openInputStream = (b2 == null || !str6.startsWith("bundle-assets://")) ? b2 == null ? ReactNativeBlobUtilImpl.f6866b.getContentResolver().openInputStream(Uri.parse(str6)) : new FileInputStream(new File(str6)) : ReactNativeBlobUtilImpl.f6866b.getAssets().open(str6.replace("bundle-assets://", ""));
                    boolean equalsIgnoreCase = str4.equalsIgnoreCase("utf8");
                    int i5 = r5;
                    int i6 = -1;
                    String str7 = "data";
                    if (equalsIgnoreCase) {
                        InputStreamReader inputStreamReader = new InputStreamReader(openInputStream, Charset.forName("UTF-8"));
                        BufferedReader bufferedReader = new BufferedReader(inputStreamReader, i3);
                        char[] cArr = new char[i3];
                        for (int i7 = 0; bufferedReader.read(cArr, i7, i3) != -1; i7 = 0) {
                            reactNativeBlobUtilStream.b(str5, "data", new String(cArr));
                            if (i5 > 0) {
                                SystemClock.sleep(i5);
                            }
                        }
                        bufferedReader.close();
                        inputStreamReader.close();
                    } else if (str4.equalsIgnoreCase("ascii")) {
                        byte[] bArr = new byte[i3];
                        while (true) {
                            int read = openInputStream.read(bArr);
                            if (read == -1) {
                                break;
                            }
                            WritableArray createArray = Arguments.createArray();
                            for (int i8 = 0; i8 < read; i8++) {
                                createArray.pushInt(bArr[i8]);
                            }
                            reactNativeBlobUtilStream.a(str5, createArray);
                            if (i5 > 0) {
                                SystemClock.sleep(i5);
                            }
                        }
                    } else {
                        if (!str4.equalsIgnoreCase("base64")) {
                            reactNativeBlobUtilStream.c(str5, "EINVAL", "Unrecognized encoding `" + str4 + "`, should be one of `base64`, `utf8`, `ascii`");
                            openInputStream.close();
                        }
                        byte[] bArr2 = new byte[i3];
                        while (true) {
                            int read2 = openInputStream.read(bArr2);
                            if (read2 == i6) {
                                break;
                            }
                            if (read2 < i3) {
                                byte[] bArr3 = new byte[read2];
                                System.arraycopy(bArr2, 0, bArr3, 0, read2);
                                reactNativeBlobUtilStream.b(str5, str7, Base64.encodeToString(bArr3, 2));
                            } else {
                                reactNativeBlobUtilStream.b(str5, str7, Base64.encodeToString(bArr2, 2));
                            }
                            if (i5 > 0) {
                                SystemClock.sleep(i5);
                                str7 = str7;
                                i6 = -1;
                            }
                        }
                    }
                    reactNativeBlobUtilStream.b(str5, "end", "");
                    openInputStream.close();
                } catch (FileNotFoundException unused) {
                    reactNativeBlobUtilStream.c(str5, "ENOENT", a.D("No such file '", str6, "'"));
                } catch (Exception e) {
                    reactNativeBlobUtilStream.c(str5, "EUNSPECIFIED", a.D("Failed to convert data to ", str4, " encoded string. This might be because this encoding cannot be used for this data."));
                    e.printStackTrace();
                }
            }
        });
    }

    @ReactMethod
    public void removeListeners(Integer num) {
    }

    @ReactMethod
    public void removeSession(ReadableArray readableArray, Callback callback) {
        this.delegate.getClass();
        new AsyncTask<ReadableArray, Integer, Integer>() {

            public final Callback f6865a;

            public AnonymousClass3(Callback callback2) {
                r1 = callback2;
            }

            @Override
            public final Integer doInBackground(ReadableArray[] readableArrayArr) {
                ReadableArray[] readableArrayArr2 = readableArrayArr;
                Callback callback2 = r1;
                try {
                    ArrayList arrayList = new ArrayList();
                    for (int i = 0; i < readableArrayArr2[0].size(); i++) {
                        String string = readableArrayArr2[0].getString(i);
                        File file = new File(string);
                        if (file.exists() && !file.delete()) {
                            arrayList.add(string);
                        }
                    }
                    if (arrayList.isEmpty()) {
                        callback2.invoke(new Object[]{null, Boolean.TRUE});
                    } else {
                        StringBuilder sb = new StringBuilder();
                        sb.append("Failed to delete: ");
                        Iterator it = arrayList.iterator();
                        while (it.hasNext()) {
                            sb.append((String) it.next());
                            sb.append(", ");
                        }
                        callback2.invoke(new Object[]{sb.toString()});
                    }
                } catch (Exception e) {
                    callback2.invoke(new Object[]{e.getLocalizedMessage()});
                }
                return Integer.valueOf(readableArrayArr2[0].size());
            }
        }.execute(readableArray);
    }

    @ReactMethod
    public void scanFile(ReadableArray readableArray, Callback callback) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final ReadableArray f6895a;

            public final ReactApplicationContext f6896b;

            public final Callback f6897c;

            public AnonymousClass9(ReadableArray readableArray2, ReactApplicationContext reactApplicationContext, Callback callback2) {
                r1 = readableArray2;
                r2 = reactApplicationContext;
                r3 = callback2;
            }

            @Override
            public final void run() {
                ReadableArray readableArray2 = r1;
                int size = readableArray2.size();
                String[] strArr = new String[size];
                String[] strArr2 = new String[size];
                for (int i = 0; i < size; i++) {
                    ReadableMap map = readableArray2.getMap(i);
                    if (map.hasKey("path")) {
                        strArr[i] = map.getString("path");
                        if (map.hasKey("mime")) {
                            strArr2[i] = map.getString("mime");
                        } else {
                            strArr2[i] = null;
                        }
                    }
                }
                ReactNativeBlobUtilFS reactNativeBlobUtilFS = new ReactNativeBlobUtilFS();
                ReactApplicationContext reactApplicationContext = r2;
                reactNativeBlobUtilFS.f6862a = reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
                final Callback callback2 = r3;
                try {
                    MediaScannerConnection.scanFile(reactApplicationContext, strArr, strArr2, new MediaScannerConnection.OnScanCompletedListener() {

                        public final Callback f6864a;

                        public AnonymousClass2(final Callback callback22) {
                            r1 = callback22;
                        }

                        @Override
                        public final void onScanCompleted(String str, Uri uri) {
                            r1.invoke(new Object[]{null, Boolean.TRUE});
                        }
                    });
                } catch (Exception e) {
                    callback22.invoke(new Object[]{e.getLocalizedMessage(), null});
                }
            }
        });
    }

    @ReactMethod
    public void slice(String str, String str2, int i, int i2, Promise promise) {
        this.delegate.getClass();
        try {
            String b2 = ReactNativeBlobUtilUtils.b(str);
            String b3 = ReactNativeBlobUtilUtils.b(str2);
            File file = new File(b2);
            if (file.isDirectory()) {
                promise.reject("EISDIR", "Expecting a file but '" + b2 + "' is a directory");
                return;
            }
            if (!file.exists()) {
                promise.reject("ENOENT", "No such file '" + b2 + "'");
                return;
            }
            int length = (int) file.length();
            int min = Math.min(length, i2) - i;
            FileInputStream fileInputStream = new FileInputStream(new File(b2));
            FileOutputStream fileOutputStream = new FileOutputStream(new File(b3));
            int skip = (int) fileInputStream.skip(i);
            if (skip != i) {
                promise.reject("EUNSPECIFIED", "Skipped " + skip + " instead of the specified " + i + " bytes, size is " + length);
                return;
            }
            byte[] bArr = new byte[10240];
            int i3 = 0;
            while (i3 < min) {
                int read = fileInputStream.read(bArr, 0, 10240);
                int i4 = min - i3;
                if (read <= 0) {
                    break;
                }
                fileOutputStream.write(bArr, 0, Math.min(i4, read));
                i3 += read;
            }
            fileInputStream.close();
            fileOutputStream.flush();
            fileOutputStream.close();
            promise.resolve(b3);
        } catch (Exception e) {
            e.printStackTrace();
            promise.reject("EUNSPECIFIED", e.getLocalizedMessage());
        }
    }

    @ReactMethod
    public void stat(String str, Callback callback) {
        this.delegate.getClass();
        try {
            String b2 = ReactNativeBlobUtilUtils.b(str);
            WritableMap g = ReactNativeBlobUtilFS.g(b2);
            if (g == null) {
                callback.invoke(new Object[]{"failed to stat path `" + b2 + "` because it does not exist or it is not a folder", null});
            } else {
                callback.invoke(new Object[]{null, g});
            }
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage()});
        }
    }

    @ReactMethod
    public void unlink(String str, Callback callback) {
        this.delegate.getClass();
        try {
            ReactNativeBlobUtilFS.a(new File(ReactNativeBlobUtilUtils.b(str)));
            callback.invoke(new Object[]{null, Boolean.TRUE});
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage(), Boolean.FALSE});
        }
    }

    @ReactMethod
    public void writeArrayChunk(String str, ReadableArray readableArray, Callback callback) {
        this.delegate.getClass();
        try {
            FileOutputStream fileOutputStream = ((ReactNativeBlobUtilStream) ReactNativeBlobUtilStream.d.get(str)).f6927c;
            byte[] bArr = new byte[readableArray.size()];
            for (int i = 0; i < readableArray.size(); i++) {
                bArr[i] = (byte) readableArray.getInt(i);
            }
            fileOutputStream.write(bArr);
            callback.invoke(new Object[0]);
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage()});
        }
    }

    @ReactMethod
    public void writeChunk(String str, String str2, Callback callback) {
        this.delegate.getClass();
        ReactNativeBlobUtilStream reactNativeBlobUtilStream = (ReactNativeBlobUtilStream) ReactNativeBlobUtilStream.d.get(str);
        try {
            reactNativeBlobUtilStream.f6927c.write(ReactNativeBlobUtilUtils.c(str2, reactNativeBlobUtilStream.f6926b));
            callback.invoke(new Object[0]);
        } catch (Exception e) {
            callback.invoke(new Object[]{e.getLocalizedMessage()});
        }
    }

    @ReactMethod
    public void writeFile(String str, String str2, String str3, boolean z, boolean z2, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6892a;

            public final String f6893b;

            public final String f6894c;
            public final boolean d;
            public final boolean e;
            public final Promise f;

            public AnonymousClass8(String str4, String str22, String str32, boolean z3, boolean z22, Promise promise2) {
                r1 = str4;
                r2 = str22;
                r3 = str32;
                r4 = z3;
                r5 = z22;
                r6 = promise2;
            }

            @Override
            public final void run() {
                int length;
                FileOutputStream fileOutputStream;
                String str4 = r1;
                String str5 = r2;
                Promise promise2 = r6;
                try {
                    File file = new File(str4);
                    File parentFile = file.getParentFile();
                    if (!file.exists()) {
                        if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs() && !parentFile.exists()) {
                            promise2.reject("EUNSPECIFIED", "Failed to create parent directory of '" + str4 + "'");
                            return;
                        }
                        if (!file.createNewFile()) {
                            promise2.reject("ENOENT", "File '" + str4 + "' does not exist and could not be created");
                            return;
                        }
                    }
                    boolean equalsIgnoreCase = str5.equalsIgnoreCase("uri");
                    String str6 = r3;
                    boolean z3 = r5;
                    if (equalsIgnoreCase) {
                        String b2 = ReactNativeBlobUtilUtils.b(str6);
                        File file2 = new File(b2);
                        if (!file2.exists()) {
                            promise2.reject("ENOENT", "No such file '" + str4 + "' ('" + b2 + "')");
                            return;
                        }
                        byte[] bArr = new byte[10240];
                        FileInputStream fileInputStream = null;
                        try {
                            FileInputStream fileInputStream2 = new FileInputStream(file2);
                            try {
                                fileOutputStream = new FileOutputStream(file, z3);
                                length = 0;
                                while (true) {
                                    try {
                                        int read = fileInputStream2.read(bArr);
                                        if (read <= 0) {
                                            break;
                                        }
                                        fileOutputStream.write(bArr, 0, read);
                                        length += read;
                                    } catch (Throwable th) {
                                        th = th;
                                        fileInputStream = fileInputStream2;
                                        if (fileInputStream != null) {
                                            fileInputStream.close();
                                        }
                                        if (fileOutputStream != null) {
                                            fileOutputStream.close();
                                        }
                                        throw th;
                                    }
                                }
                                fileInputStream2.close();
                                fileOutputStream.close();
                            } catch (Throwable th2) {
                                th = th2;
                                fileOutputStream = null;
                            }
                        } catch (Throwable th3) {
                            th = th3;
                            fileOutputStream = null;
                        }
                    } else {
                        byte[] c2 = ReactNativeBlobUtilUtils.c(str6, str5);
                        if (r4) {
                            throw new IllegalStateException("Write file with transform was specified but the shared file transformer is not set");
                        }
                        FileOutputStream fileOutputStream2 = new FileOutputStream(file, z3);
                        try {
                            fileOutputStream2.write(c2);
                            length = c2.length;
                        } finally {
                            fileOutputStream2.close();
                        }
                    }
                    promise2.resolve(Integer.valueOf(length));
                } catch (FileNotFoundException unused) {
                    promise2.reject("ENOENT", "File '" + str4 + "' does not exist and could not be created, or it is a directory");
                } catch (Exception e) {
                    promise2.reject("EUNSPECIFIED", e.getLocalizedMessage());
                }
            }
        });
    }

    @ReactMethod
    public void writeFileArray(String str, ReadableArray readableArray, boolean z, Promise promise) {
        this.delegate.getClass();
        ReactNativeBlobUtilImpl.f6867c.execute(new Runnable() {

            public final String f6889a;

            public final ReadableArray f6890b;

            public final boolean f6891c;
            public final Promise d;

            public AnonymousClass7(String str2, ReadableArray readableArray2, boolean z2, Promise promise2) {
                r1 = str2;
                r2 = readableArray2;
                r3 = z2;
                r4 = promise2;
            }

            @Override
            public final void run() {
                String str2 = r1;
                ReadableArray readableArray2 = r2;
                boolean z2 = r3;
                Promise promise2 = r4;
                try {
                    File file = new File(str2);
                    File parentFile = file.getParentFile();
                    if (!file.exists()) {
                        if (parentFile != null && !parentFile.exists() && !parentFile.mkdirs() && !parentFile.exists()) {
                            promise2.reject("ENOTDIR", "Failed to create parent directory of '" + str2 + "'");
                            return;
                        }
                        if (!file.createNewFile()) {
                            promise2.reject("ENOENT", "File '" + str2 + "' does not exist and could not be created");
                            return;
                        }
                    }
                    FileOutputStream fileOutputStream = new FileOutputStream(file, z2);
                    try {
                        byte[] bArr = new byte[readableArray2.size()];
                        for (int i = 0; i < readableArray2.size(); i++) {
                            bArr[i] = (byte) readableArray2.getInt(i);
                        }
                        fileOutputStream.write(bArr);
                        fileOutputStream.close();
                        promise2.resolve(Integer.valueOf(readableArray2.size()));
                    } catch (Throwable th) {
                        fileOutputStream.close();
                        throw th;
                    }
                } catch (FileNotFoundException unused) {
                    promise2.reject("ENOENT", "File '" + str2 + "' does not exist and could not be created");
                } catch (Exception e) {
                    promise2.reject("EUNSPECIFIED", e.getLocalizedMessage());
                }
            }
        });
    }

    @ReactMethod
    public void writeStream(String str, String str2, boolean z, Callback callback) {
        this.delegate.getClass();
        ReactNativeBlobUtilStream reactNativeBlobUtilStream = new ReactNativeBlobUtilStream(ReactNativeBlobUtilImpl.f6866b);
        try {
            File file = new File(str);
            File parentFile = file.getParentFile();
            if (file.exists()) {
                if (file.isDirectory()) {
                    callback.invoke(new Object[]{"EISDIR", "Expecting a file but '" + str + "' is a directory"});
                }
                FileOutputStream fileOutputStream = new FileOutputStream(str, z);
                reactNativeBlobUtilStream.f6926b = str2;
                String uuid = UUID.randomUUID().toString();
                ReactNativeBlobUtilStream.d.put(uuid, reactNativeBlobUtilStream);
                reactNativeBlobUtilStream.f6927c = fileOutputStream;
                callback.invoke(new Object[]{null, null, uuid});
            }
            if (parentFile == null || parentFile.exists() || parentFile.mkdirs()) {
                if (!file.createNewFile()) {
                    callback.invoke(new Object[]{"ENOENT", "File '" + str + "' does not exist and could not be created"});
                }
                FileOutputStream fileOutputStream2 = new FileOutputStream(str, z);
                reactNativeBlobUtilStream.f6926b = str2;
                String uuid2 = UUID.randomUUID().toString();
                ReactNativeBlobUtilStream.d.put(uuid2, reactNativeBlobUtilStream);
                reactNativeBlobUtilStream.f6927c = fileOutputStream2;
                callback.invoke(new Object[]{null, null, uuid2});
            } else {
                callback.invoke(new Object[]{"ENOTDIR", "Failed to create parent directory of '" + str + "'"});
            }
        } catch (Exception e) {
            StringBuilder y = a.y("Failed to create write stream at path `", str, "`; ");
            y.append(e.getLocalizedMessage());
            callback.invoke(new Object[]{"EUNSPECIFIED", y.toString()});
        }
    }

    @ReactMethod
    public void writeToMediaFile(String str, String str2, boolean z, Promise promise) {
        this.delegate.getClass();
        if (ReactNativeBlobUtilMediaCollection.b(Uri.parse(str), str2, z, promise, ReactNativeBlobUtilImpl.f6866b)) {
            promise.resolve("Success");
        }
    }
}