what-the-bank/sources/com/kofax/kmc/ken/engines/service/FileService.java

131 lines
4.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.kofax.kmc.ken.engines.service;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import com.kofax.mobile.sdk._internal.k;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
/* loaded from: classes3.dex */
public class FileService {
private static final String TAG = "FileService";
public static boolean deleteDirectory(File file) {
StringBuilder sb = new StringBuilder("Deleting directory/file - ");
sb.append(file.getAbsolutePath());
k.b("UtilsService.deleteDirectory", sb.toString());
if (file.isDirectory()) {
for (String str : file.list()) {
if (!deleteDirectory(new File(file, str))) {
return false;
}
}
}
return file.delete();
}
public static String getDocumentPath(Context context) {
if (Environment.getExternalStorageState().equals("mounted")) {
File externalStoragePublicDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
externalStoragePublicDirectory.mkdirs();
return externalStoragePublicDirectory.getAbsolutePath();
}
return context.getFilesDir().getAbsolutePath();
}
public static String getLocalPath(Context context) {
return context.getFilesDir().getAbsolutePath();
}
public static boolean copyFile(String str, String str2) throws IOException {
return copyFile(new File(str), new File(str2));
}
public static boolean copyFile(File file, File file2) throws IOException {
Throwable th;
FileChannel fileChannel;
String str = TAG;
StringBuilder sb = new StringBuilder("Copying from '");
sb.append(file);
sb.append("' to '");
sb.append(file2);
sb.append("'");
k.b(str, sb.toString());
if (file2.exists()) {
k.b(str, "... destination exists. Deleting.");
file2.delete();
file2.createNewFile();
} else {
file2.createNewFile();
}
FileChannel fileChannel2 = null;
try {
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
try {
FileChannel channel2 = new RandomAccessFile(file2, "rw").getChannel();
try {
channel.transferTo(0L, channel.size(), channel2);
if (channel != null) {
channel.close();
}
if (channel2 == null) {
return false;
}
channel2.close();
return true;
} catch (Throwable th2) {
th = th2;
fileChannel2 = channel2;
FileChannel fileChannel3 = fileChannel2;
fileChannel2 = channel;
fileChannel = fileChannel3;
if (fileChannel2 != null) {
fileChannel2.close();
}
if (fileChannel != null) {
fileChannel.close();
throw th;
}
throw th;
}
} catch (Throwable th3) {
th = th3;
}
} catch (Throwable th4) {
th = th4;
fileChannel = null;
}
}
public static String getFileNameByUri(Uri uri, Context context) {
String obj;
String str = TAG;
k.b(str, "Getting filename from uri...");
StringBuilder sb = new StringBuilder("... schema -> ");
sb.append(uri.getScheme().toString());
k.b(str, sb.toString());
if (uri.getScheme().toString().compareTo("content") == 0) {
Cursor query = context.getContentResolver().query(uri, null, null, null, null);
if (query.moveToFirst()) {
int columnIndexOrThrow = query.getColumnIndexOrThrow("_data");
k.b(str, "... column_index -> ".concat(String.valueOf(columnIndexOrThrow)));
obj = Uri.parse(query.getString(columnIndexOrThrow)).getPath();
} else {
obj = null;
}
} else if (uri.getScheme().compareTo("file") == 0) {
obj = uri.getPath();
} else {
StringBuilder sb2 = new StringBuilder("null_");
sb2.append(uri.getLastPathSegment().toString());
obj = sb2.toString();
}
k.b(str, "... fileName -> ".concat(String.valueOf(obj)));
return obj;
}
}