IFile.java
1.77 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
package com.megvii.idcardlib.util;
import com.megvii.livenessdetection.DetectionFrame;
import com.megvii.livenessdetection.Detector;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
/**
* 文件工具类
*/
public class IFile {
public IFile() {
}
/**
* 把图片保存到文件夹
*/
public boolean save(Detector mDetector, String session,
JSONObject jsonObject) {
List<DetectionFrame> frames = mDetector.getValidFrame();
if (frames.size() == 0) {
return false;
}
try {
String dirPath = Constant.dirName + "/" + session;
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
for (int i = 0; i < frames.size(); i++) {
File file = new File(dir, session + "-" + i + ".jpg");
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(frames.get(i).getCroppedFaceImageData());
JSONArray jsonArray = jsonObject.getJSONArray("imgs");
jsonArray.put(file.getAbsoluteFile());
fileOutputStream.flush();
fileOutputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* 把LOG保存到本地
*/
public boolean saveLog(String session, String name) {
try {
String dirPath = Constant.dirName + "/" + session;
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, "Log.txt");
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
String str = "\n" + session + ", " + name;
fileOutputStream.write(str.getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
}