正在查看: BAM Crawford v6.14.1 应用的 RNFSManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: BAM Crawford v6.14.1 应用的 RNFSManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.rnfs;
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.rnfs.a;
import com.rnfs.g;
import com.subsplash.thechurchapp.handlers.system.EmailHandler;
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;
import okio.Segment;
@s8.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.c> downloaders;
private ReactApplicationContext reactContext;
private SparseArray<com.rnfs.i> uploaders;
class a extends j {
final File b;
final Promise c;
final String d;
a(File file, Promise promise, String str) {
super();
this.b = file;
this.c = promise;
this.d = str;
}
@Override
public void onPostExecute(Exception exc) {
if (exc == null) {
this.b.delete();
this.c.resolve(Boolean.TRUE);
} else {
exc.printStackTrace();
RNFSManager.this.reject(this.c, this.d, exc);
}
}
}
class b extends j {
final Promise b;
final String c;
b(Promise promise, String str) {
super();
this.b = promise;
this.c = str;
}
@Override
public void onPostExecute(Exception exc) {
if (exc == null) {
this.b.resolve((Object) null);
} else {
exc.printStackTrace();
RNFSManager.this.reject(this.b, this.c, exc);
}
}
}
class c implements a.c {
final int a;
final Promise b;
final ReadableMap c;
c(int i, Promise promise, ReadableMap readableMap) {
this.a = i;
this.b = promise;
this.c = readableMap;
}
@Override
public void a(com.rnfs.b bVar) {
if (bVar.c != null) {
RNFSManager.this.reject(this.b, this.c.getString("toFile"), bVar.c);
return;
}
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", this.a);
createMap.putInt("statusCode", bVar.a);
createMap.putDouble("bytesWritten", bVar.b);
this.b.resolve(createMap);
}
}
class d implements a.InterfaceC0042a {
final int a;
d(int i) {
this.a = i;
}
@Override
public void a(int i, long j, Map map) {
WritableMap createMap = Arguments.createMap();
for (Map.Entry entry : map.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);
}
}
class e implements a.b {
final int a;
e(int i) {
this.a = i;
}
@Override
public void a(long j, long j2) {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", this.a);
createMap.putDouble("contentLength", j);
createMap.putDouble("bytesWritten", j2);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "DownloadProgress", createMap);
}
}
class f implements g.b {
final int a;
final Promise b;
final ReadableMap c;
f(int i, Promise promise, ReadableMap readableMap) {
this.a = i;
this.b = promise;
this.c = readableMap;
}
@Override
public void a(com.rnfs.h hVar) {
if (hVar.c != null) {
RNFSManager.this.reject(this.b, this.c.getString("toUrl"), hVar.c);
return;
}
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", this.a);
createMap.putInt("statusCode", hVar.a);
createMap.putMap("headers", hVar.b);
createMap.putString(EmailHandler.BODY, hVar.d);
this.b.resolve(createMap);
}
}
class g implements g.a {
final int a;
g(int i) {
this.a = i;
}
@Override
public void a() {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", this.a);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "UploadBegin", createMap);
}
}
class h implements g.c {
final int a;
h(int i) {
this.a = i;
}
@Override
public void a(int i, int i2) {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", this.a);
createMap.putInt("totalBytesExpectedToSend", i);
createMap.putInt("totalBytesSent", i2);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "UploadProgress", createMap);
}
}
class i implements MediaScannerConnection.MediaScannerConnectionClient {
final Promise a;
i(Promise promise) {
this.a = promise;
}
@Override
public void onMediaScannerConnected() {
}
@Override
public void onScanCompleted(String str, Uri uri) {
this.a.resolve(str);
}
}
private class j extends AsyncTask {
@Override
public Exception doInBackground(String... strArr) {
try {
String str = strArr[0];
String str2 = strArr[1];
InputStream inputStream = RNFSManager.this.getInputStream(str);
OutputStream outputStream = RNFSManager.this.getOutputStream(str2, false);
byte[] bArr = new byte[Segment.SHARE_MINIMUM];
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;
}
}
private j() {
}
}
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) {
Uri parse = Uri.parse(str);
if (parse.getScheme() != null) {
return parse;
}
File file = new File(str);
if (z || !file.isDirectory()) {
return Uri.parse("file://" + str);
}
throw new com.rnfs.d("EISDIR", "EISDIR: illegal operation on a directory, read '" + str + "'");
}
public InputStream getInputStream(String str) {
try {
InputStream openInputStream = this.reactContext.getContentResolver().openInputStream(getFileUri(str, false));
if (openInputStream != null) {
return openInputStream;
}
throw new com.rnfs.d("ENOENT", "ENOENT: could not open an input stream for '" + str + "'");
} catch (FileNotFoundException e2) {
throw new com.rnfs.d("ENOENT", "ENOENT: " + e2.getMessage() + ", open '" + str + "'");
}
}
private static byte[] getInputStreamBytes(InputStream inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr = new byte[Segment.SHARE_MINIMUM];
while (true) {
try {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
byteArrayOutputStream.write(bArr, 0, read);
} finally {
try {
byteArrayOutputStream.close();
} catch (IOException unused) {
}
}
}
return byteArrayOutputStream.toByteArray();
}
private String getOriginalFilepath(String str, boolean z) {
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) {
try {
OutputStream openOutputStream = this.reactContext.getContentResolver().openOutputStream(getFileUri(str, false), z ? "wa" : getWriteAccessByAPILevel());
if (openOutputStream != null) {
return openOutputStream;
}
throw new com.rnfs.d("ENOENT", "ENOENT: could not open an output stream for '" + str + "'");
} catch (FileNotFoundException e2) {
throw new com.rnfs.d("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.d)) {
promise.reject((String) null, exc.getMessage());
} else {
com.rnfs.d dVar = (com.rnfs.d) exc;
promise.reject(dVar.a(), dVar.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 addListener(String str) {
}
@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.c cVar = new com.rnfs.c();
cVar.execute(aVar);
this.downloaders.put(i2, cVar);
} 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 th2) {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception unused4) {
}
}
throw th2;
}
} 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", Byte.valueOf(b2)));
}
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 pathForBundle(String str, Promise promise) {
}
@ReactMethod
public void pathForGroup(String str, Promise promise) {
}
@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);
}
}
@com.facebook.react.bridge.ReactMethod
public void readDirAssets(java.lang.String r12, com.facebook.react.bridge.Promise r13) {
throw new UnsupportedOperationException("Method not decompiled: com.rnfs.RNFSManager.readDirAssets(java.lang.String, com.facebook.react.bridge.Promise):void");
}
@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 th2) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException unused) {
}
}
throw th2;
}
} 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 (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 unused) {
return;
}
}
return;
}
byte[] bArr = new byte[inputStream.available()];
inputStream.read(bArr);
promise.resolve(Base64.encodeToString(bArr, 2));
try {
inputStream.close();
} catch (IOException unused2) {
}
} catch (Throwable th2) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException unused3) {
}
}
throw th2;
}
}
@ReactMethod
public void removeListeners(Integer num) {
}
@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) {
int i2 = 1;
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());
if (!file.isDirectory()) {
i2 = 0;
}
createMap.putInt("type", i2);
createMap.putString("originalFilepath", originalFilepath);
promise.resolve(createMap);
} catch (Exception e2) {
e2.printStackTrace();
reject(promise, str, e2);
}
}
@ReactMethod
public void stopDownload(int i2) {
com.rnfs.c cVar = this.downloaders.get(i2);
if (cVar != null) {
cVar.g();
}
}
@ReactMethod
public void stopUpload(int i2) {
com.rnfs.i iVar = this.uploaders.get(i2);
if (iVar != null) {
iVar.f();
}
}
@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 arrayList = new ArrayList();
com.rnfs.g gVar = new com.rnfs.g();
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;
}
}
gVar.a = url;
gVar.b = arrayList;
gVar.d = map;
gVar.f = string;
gVar.e = map2;
gVar.c = z;
gVar.g = new f(i2, promise, readableMap);
if (z2) {
gVar.i = new g(i2);
}
if (z3) {
gVar.h = new h(i2);
}
com.rnfs.i iVar = new com.rnfs.i();
iVar.execute(gVar);
this.uploaders.put(i2, iVar);
} 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);
}
}
}