正在查看: aeroLINE CREW v5.0.1 应用的 RNFSManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: aeroLINE CREW v5.0.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.module.annotations.ReactModule;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.rnfs.DownloadParams;
import com.rnfs.UploadParams;
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;
@ReactModule(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<Downloader> downloaders;
private ReactApplicationContext reactContext;
private SparseArray<Uploader> uploaders;
@ReactMethod
public void addListener(String str) {
}
public String getName() {
return MODULE_NAME;
}
@ReactMethod
public void pathForBundle(String str, Promise promise) {
}
@ReactMethod
public void pathForGroup(String str, Promise promise) {
}
@ReactMethod
public void removeListeners(Integer num) {
}
public RNFSManager(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
this.downloaders = new SparseArray<>();
this.uploaders = new SparseArray<>();
this.reactContext = reactApplicationContext;
}
private Uri getFileUri(String str, boolean z) throws IORejectionException {
Uri parse = Uri.parse(str);
if (parse.getScheme() != null) {
return parse;
}
File file = new File(str);
if (!z && file.isDirectory()) {
throw new IORejectionException("EISDIR", "EISDIR: illegal operation on a directory, read '" + str + "'");
}
return Uri.parse("file://" + str);
}
private String getOriginalFilepath(String str, boolean z) throws IORejectionException {
Uri fileUri = getFileUri(str, z);
if (fileUri.getScheme().equals(FirebaseAnalytics.Param.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 InputStream getInputStream(String str) throws IORejectionException {
try {
InputStream openInputStream = this.reactContext.getContentResolver().openInputStream(getFileUri(str, false));
if (openInputStream != null) {
return openInputStream;
}
throw new IORejectionException("ENOENT", "ENOENT: could not open an input stream for '" + str + "'");
} catch (FileNotFoundException e) {
throw new IORejectionException("ENOENT", "ENOENT: " + e.getMessage() + ", open '" + str + "'");
}
}
private String getWriteAccessByAPILevel() {
return Build.VERSION.SDK_INT <= 28 ? "w" : "rwt";
}
public OutputStream getOutputStream(String str, boolean z) throws IORejectionException {
try {
OutputStream openOutputStream = this.reactContext.getContentResolver().openOutputStream(getFileUri(str, false), z ? "wa" : getWriteAccessByAPILevel());
if (openOutputStream != null) {
return openOutputStream;
}
throw new IORejectionException("ENOENT", "ENOENT: could not open an output stream for '" + str + "'");
} catch (FileNotFoundException e) {
throw new IORejectionException("ENOENT", "ENOENT: " + e.getMessage() + ", open '" + str + "'");
}
}
private static byte[] getInputStreamBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr = new byte[1024];
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();
}
@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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void write(String str, String str2, int i, Promise promise) {
try {
byte[] decode = Base64.decode(str2, 0);
if (i < 0) {
OutputStream outputStream = getOutputStream(str, true);
outputStream.write(decode);
outputStream.close();
} else {
RandomAccessFile randomAccessFile = new RandomAccessFile(str, "rw");
randomAccessFile.seek(i);
randomAccessFile.write(decode);
randomAccessFile.close();
}
promise.resolve((Object) null);
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void exists(String str, Promise promise) {
try {
promise.resolve(Boolean.valueOf(new File(str).exists()));
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void readFile(String str, Promise promise) {
try {
promise.resolve(Base64.encodeToString(getInputStreamBytes(getInputStream(str)), 2));
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void read(String str, int i, int i2, Promise promise) {
try {
InputStream inputStream = getInputStream(str);
byte[] bArr = new byte[i];
inputStream.skip(i2);
promise.resolve(Base64.encodeToString(bArr, 0, inputStream.read(bArr, 0, i), 2));
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void readFileAssets(String str, Promise promise) {
InputStream inputStream = null;
try {
try {
inputStream = getReactApplicationContext().getAssets().open(str, 0);
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
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));
if (inputStream == null) {
return;
}
try {
inputStream.close();
} catch (IOException unused2) {
}
} catch (Throwable th) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException unused3) {
}
}
throw th;
}
}
@ReactMethod
public void readFileRes(String str, Promise promise) {
InputStream inputStream = null;
try {
try {
inputStream = getReactApplicationContext().getResources().openRawResource(getResIdentifier(str));
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
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));
if (inputStream == null) {
return;
}
try {
inputStream.close();
} catch (IOException unused2) {
}
} catch (Throwable th) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException unused3) {
}
}
throw th;
}
}
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());
}
@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 b : messageDigest.digest()) {
sb.append(String.format("%02x", Byte.valueOf(b)));
}
promise.resolve(sb.toString());
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void moveFile(final String str, String str2, ReadableMap readableMap, final Promise promise) {
try {
final File file = new File(str);
if (!file.renameTo(new File(str2))) {
new CopyFileTask() {
{
super();
}
@Override
public void onPostExecute(Exception exc) {
if (exc == null) {
file.delete();
promise.resolve(true);
} else {
exc.printStackTrace();
RNFSManager.this.reject(promise, str, exc);
}
}
}.execute(new String[]{str, str2});
} else {
promise.resolve(true);
}
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void copyFile(final String str, String str2, ReadableMap readableMap, final Promise promise) {
new CopyFileTask() {
{
super();
}
@Override
public void onPostExecute(Exception exc) {
if (exc == null) {
promise.resolve((Object) null);
} else {
exc.printStackTrace();
RNFSManager.this.reject(promise, str, exc);
}
}
}.execute(new String[]{str, str2});
}
private class CopyFileTask extends AsyncTask<String, Void, Exception> {
private CopyFileTask() {
}
@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[1024];
while (true) {
int read = inputStream.read(bArr);
if (read > 0) {
outputStream.write(bArr, 0, read);
Thread.yield();
} else {
inputStream.close();
outputStream.close();
return null;
}
}
} catch (Exception e) {
return e;
}
}
}
@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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@com.facebook.react.bridge.ReactMethod
public void readDirAssets(java.lang.String r13, com.facebook.react.bridge.Promise r14) {
throw new UnsupportedOperationException("Method not decompiled: com.rnfs.RNFSManager.readDirAssets(java.lang.String, com.facebook.react.bridge.Promise):void");
}
@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 existsAssets(String str, Promise promise) {
try {
AssetManager assets = getReactApplicationContext().getAssets();
try {
String[] list = assets.list(str);
if (list != null && list.length > 0) {
promise.resolve(true);
return;
}
} catch (Exception unused) {
}
InputStream inputStream = null;
try {
try {
inputStream = assets.open(str);
promise.resolve(true);
if (inputStream == null) {
return;
}
} catch (Exception unused2) {
promise.resolve(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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void existsRes(String str, Promise promise) {
try {
if (getResIdentifier(str) > 0) {
promise.resolve(true);
} else {
promise.resolve(false);
}
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
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");
}
@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(true);
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void stat(String str, Promise promise) {
int i = 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()) {
i = 0;
}
createMap.putInt("type", i);
createMap.putString("originalFilepath", originalFilepath);
promise.resolve(createMap);
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
private void DeleteRecursive(File file) {
if (file.isDirectory()) {
for (File file2 : file.listFiles()) {
DeleteRecursive(file2);
}
}
file.delete();
}
@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 e) {
e.printStackTrace();
reject(promise, str, e);
}
}
public void sendEvent(ReactContext reactContext, String str, WritableMap writableMap) {
reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(str, writableMap);
}
@ReactMethod
public void downloadFile(final ReadableMap readableMap, final Promise promise) {
try {
File file = new File(readableMap.getString("toFile"));
URL url = new URL(readableMap.getString("fromUrl"));
final int i = readableMap.getInt("jobId");
ReadableMap map = readableMap.getMap("headers");
int i2 = readableMap.getInt("progressInterval");
int i3 = readableMap.getInt("progressDivider");
int i4 = readableMap.getInt("readTimeout");
int i5 = readableMap.getInt("connectionTimeout");
boolean z = readableMap.getBoolean("hasBeginCallback");
boolean z2 = readableMap.getBoolean("hasProgressCallback");
DownloadParams downloadParams = new DownloadParams();
downloadParams.src = url;
downloadParams.dest = file;
downloadParams.headers = map;
downloadParams.progressInterval = i2;
downloadParams.progressDivider = i3;
downloadParams.readTimeout = i4;
downloadParams.connectionTimeout = i5;
downloadParams.onTaskCompleted = new DownloadParams.OnTaskCompleted() {
@Override
public void onTaskCompleted(DownloadResult downloadResult) {
if (downloadResult.exception != null) {
RNFSManager.this.reject(promise, readableMap.getString("toFile"), downloadResult.exception);
return;
}
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", i);
createMap.putInt("statusCode", downloadResult.statusCode);
createMap.putDouble("bytesWritten", downloadResult.bytesWritten);
promise.resolve(createMap);
}
};
if (z) {
downloadParams.onDownloadBegin = new DownloadParams.OnDownloadBegin() {
@Override
public void onDownloadBegin(int i6, long j, Map<String, String> map2) {
WritableMap createMap = Arguments.createMap();
for (Map.Entry<String, String> entry : map2.entrySet()) {
createMap.putString(entry.getKey(), entry.getValue());
}
WritableMap createMap2 = Arguments.createMap();
createMap2.putInt("jobId", i);
createMap2.putInt("statusCode", i6);
createMap2.putDouble("contentLength", j);
createMap2.putMap("headers", createMap);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "DownloadBegin", createMap2);
}
};
}
if (z2) {
downloadParams.onDownloadProgress = new DownloadParams.OnDownloadProgress() {
@Override
public void onDownloadProgress(long j, long j2) {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", i);
createMap.putDouble("contentLength", j);
createMap.putDouble("bytesWritten", j2);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "DownloadProgress", createMap);
}
};
}
Downloader downloader = new Downloader();
downloader.execute(downloadParams);
this.downloaders.put(i, downloader);
} catch (Exception e) {
e.printStackTrace();
reject(promise, readableMap.getString("toFile"), e);
}
}
@ReactMethod
public void stopDownload(int i) {
Downloader downloader = this.downloaders.get(i);
if (downloader != null) {
downloader.stop();
}
}
@ReactMethod
public void uploadFiles(final ReadableMap readableMap, final Promise promise) {
String str;
try {
ReadableArray array = readableMap.getArray("files");
URL url = new URL(readableMap.getString("toUrl"));
final int i = readableMap.getInt("jobId");
ReadableMap map = readableMap.getMap("headers");
ReadableMap map2 = readableMap.getMap("fields");
String string = readableMap.getString(FirebaseAnalytics.Param.METHOD);
boolean z = readableMap.getBoolean("binaryStreamOnly");
boolean z2 = readableMap.getBoolean("hasBeginCallback");
boolean z3 = readableMap.getBoolean("hasProgressCallback");
ArrayList<ReadableMap> arrayList = new ArrayList<>();
UploadParams uploadParams = new UploadParams();
str = "toUrl";
for (int i2 = 0; i2 < array.size(); i2++) {
try {
arrayList.add(array.getMap(i2));
} catch (Exception e) {
e = e;
e.printStackTrace();
reject(promise, readableMap.getString(str), e);
return;
}
}
uploadParams.src = url;
uploadParams.files = arrayList;
uploadParams.headers = map;
uploadParams.method = string;
uploadParams.fields = map2;
uploadParams.binaryStreamOnly = z;
uploadParams.onUploadComplete = new UploadParams.onUploadComplete() {
@Override
public void onUploadComplete(UploadResult uploadResult) {
if (uploadResult.exception != null) {
RNFSManager.this.reject(promise, readableMap.getString("toUrl"), uploadResult.exception);
return;
}
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", i);
createMap.putInt("statusCode", uploadResult.statusCode);
createMap.putMap("headers", uploadResult.headers);
createMap.putString("body", uploadResult.body);
promise.resolve(createMap);
}
};
if (z2) {
uploadParams.onUploadBegin = new UploadParams.onUploadBegin() {
@Override
public void onUploadBegin() {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", i);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "UploadBegin", createMap);
}
};
}
if (z3) {
uploadParams.onUploadProgress = new UploadParams.onUploadProgress() {
@Override
public void onUploadProgress(int i3, int i4) {
WritableMap createMap = Arguments.createMap();
createMap.putInt("jobId", i);
createMap.putInt("totalBytesExpectedToSend", i3);
createMap.putInt("totalBytesSent", i4);
RNFSManager rNFSManager = RNFSManager.this;
rNFSManager.sendEvent(rNFSManager.getReactApplicationContext(), "UploadProgress", createMap);
}
};
}
Uploader uploader = new Uploader();
uploader.execute(uploadParams);
this.uploaders.put(i, uploader);
} catch (Exception e2) {
e = e2;
str = "toUrl";
}
}
@ReactMethod
public void stopUpload(int i) {
Uploader uploader = this.uploaders.get(i);
if (uploader != null) {
uploader.stop();
}
}
@ReactMethod
public void getFSInfo(Promise promise) {
long blockCount;
long availableBlocks;
long j;
long j2;
StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
StatFs statFs2 = new StatFs(Environment.getExternalStorageDirectory().getPath());
if (Build.VERSION.SDK_INT >= 18) {
blockCount = statFs.getTotalBytes();
availableBlocks = statFs.getFreeBytes();
j2 = statFs2.getTotalBytes();
j = statFs2.getFreeBytes();
} else {
long blockSize = statFs.getBlockSize();
blockCount = statFs.getBlockCount() * blockSize;
availableBlocks = statFs.getAvailableBlocks() * blockSize;
j = 0;
j2 = 0;
}
WritableMap createMap = Arguments.createMap();
createMap.putDouble("totalSpace", blockCount);
createMap.putDouble("freeSpace", availableBlocks);
createMap.putDouble("totalSpaceEx", j2);
createMap.putDouble("freeSpaceEx", j);
promise.resolve(createMap);
}
@ReactMethod
public void touch(String str, double d, double d2, Promise promise) {
try {
promise.resolve(Boolean.valueOf(new File(str).setLastModified((long) d)));
} catch (Exception e) {
e.printStackTrace();
reject(promise, str, e);
}
}
@ReactMethod
public void getAllExternalFilesDirs(Promise promise) {
File[] externalFilesDirs = getReactApplicationContext().getExternalFilesDirs((String) null);
WritableArray createArray = Arguments.createArray();
for (File file : externalFilesDirs) {
if (file != null) {
createArray.pushString(file.getAbsolutePath());
}
}
promise.resolve(createArray);
}
@ReactMethod
public void scanFile(String str, final Promise promise) {
MediaScannerConnection.scanFile(getReactApplicationContext(), new String[]{str}, null, new MediaScannerConnection.MediaScannerConnectionClient() {
@Override
public void onMediaScannerConnected() {
}
@Override
public void onScanCompleted(String str2, Uri uri) {
promise.resolve(str2);
}
});
}
public void reject(Promise promise, String str, Exception exc) {
if (exc instanceof FileNotFoundException) {
rejectFileNotFound(promise, str);
} else if (exc instanceof IORejectionException) {
IORejectionException iORejectionException = (IORejectionException) exc;
promise.reject(iORejectionException.getCode(), iORejectionException.getMessage());
} else {
promise.reject((String) null, exc.getMessage());
}
}
private void rejectFileNotFound(Promise promise, String str) {
promise.reject("ENOENT", "ENOENT: no such file or directory, open '" + str + "'");
}
private void rejectFileIsDirectory(Promise promise) {
promise.reject("EISDIR", "EISDIR: illegal operation on a directory, read");
}
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((String) 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;
}
}