-
Notifications
You must be signed in to change notification settings - Fork 826
Expand file tree
/
Copy pathFileUtils.java
More file actions
executable file
·111 lines (93 loc) · 3.22 KB
/
FileUtils.java
File metadata and controls
executable file
·111 lines (93 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.github.hiteshsondhi88.libffmpeg;
import android.content.Context;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
import java.util.Map;
class FileUtils {
static final String ffmpegFileName = "libffmpeg.so";
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private static final int EOF = -1;
/*
static boolean copyBinaryFromAssetsToData(Context context, String fileNameFromAssets, String outputFileName) {
// create files directory under /data/data/package name
File filesDirectory = getFilesDirectory(context);
InputStream is;
try {
is = context.getAssets().open(fileNameFromAssets);
// copy ffmpeg file from assets to files dir
final FileOutputStream os = new FileOutputStream(new File(filesDirectory, outputFileName));
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int n;
while(EOF != (n = is.read(buffer))) {
os.write(buffer, 0, n);
}
Util.close(os);
Util.close(is);
return true;
} catch (IOException e) {
Log.e("issue in coping binary from assets to data. ", e);
}
return false;
}
*/
static String getFFmpeg(Context context) {
String archFolder = "";
if (CpuArchHelper.getCpuArch() == CpuArch.x86){
archFolder = "x86";
} else if (CpuArchHelper.getCpuArch() == CpuArch.ARMv7){
archFolder = "arm";
}
return context.getPackageResourcePath().replaceAll("/([^/]+)$", "/lib/") + archFolder + "/" + ffmpegFileName;
}
static String getFFmpeg(Context context, Map<String,String> environmentVars) {
String ffmpegCommand = "";
if (environmentVars != null) {
for (Map.Entry<String, String> var : environmentVars.entrySet()) {
ffmpegCommand += var.getKey()+"="+var.getValue()+" ";
}
}
ffmpegCommand += getFFmpeg(context);
return ffmpegCommand;
}
static String SHA1(String file) {
InputStream is = null;
try {
is = new BufferedInputStream(new FileInputStream(file));
return SHA1(is);
} catch (IOException e) {
Log.e(e);
} finally {
Util.close(is);
}
return null;
}
static String SHA1(InputStream is) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
for (int read; (read = is.read(buffer)) != -1; ) {
messageDigest.update(buffer, 0, read);
}
Formatter formatter = new Formatter();
// Convert the byte to hex format
for (final byte b : messageDigest.digest()) {
formatter.format("%02x", b);
}
return formatter.toString();
} catch (NoSuchAlgorithmException e) {
Log.e(e);
} catch (IOException e) {
Log.e(e);
} finally {
Util.close(is);
}
return null;
}
}